简体   繁体   English

如何在WP7按钮中绑定内容

[英]How to bind content in WP7 button

I have earlier asked how to convert static values of TextBlocks using bindings and IValueConverter as seen here . 我刚才问到如何的静态值转换TextBlocks使用绑定和IValueConverter所看到这里

Now I would like to do the exact same thing, but with buttons instead. 现在我想做同样的事情,但用按钮代替。 But the problem is, that buttons do not have the DataContext property, so the IValueConverter is not invoked. 但问题是,按钮没有DataContext属性,因此不调用IValueConverter

So how do I achieve this? 那我该怎么做呢?

Thank you! 谢谢!

How about setting the 如何设置

Button.Content.DataContext 

?

EDIT: XAML sample fixed 编辑:XAML样本已修复

<Button Name="mmmm" 
        DataContext="{Binding MovieContext}" 
        Content="{Binding Title}" />

Buttons do have a DataContext property . 按钮确实有DataContext属性 All FrameworkElements do. 所有FrameworkElements都可以。 Why not just set the datacontext of the Page that all of these are in? 为什么不设置所有这些都在的Page的datacontext? If you set the DataContext of the page to be a backing ViewModel, then every control will inherit that DataContext. 如果将页面的DataContext设置为后备ViewModel,则每个控件都将继承该DataContext。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM