WPF 触发器绑定到 MVVM 属性 [英] WPF Trigger binding to MVVM property
本文介绍了WPF 触发器绑定到 MVVM 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含图像的数据模板,如果 ViewModel 中的属性值为 true,我希望将其隐藏.谁能告诉我为什么下面的 xaml 不起作用?
I have a datatemplate containing an image that I want to be hidden if the the value of a property in a ViewModel is true. Can anyone tell me why the the xaml below does not work?
<Image x:Name="img" Source="..ImagesList_16.png" Margin="0,0,5,0">
<Image.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding CurrentListHasPendingChanges}" Value="True">
<Setter Property="Image.Visibility" Value="Hidden" />
</DataTrigger>
<DataTrigger Binding="{Binding CurrentListHasPendingChanges}" Value="False">
<Setter Property="Image.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
推荐答案
不是这样的
<Setter Property="Visibility" Value="Hidden" />
?
我假设您使用 INotifyProptyChanged.
I assume you use INotifyProptyChanged.
编辑我做了一些谷歌搜索,我认为你需要使用某种模板才能使触发器工作.
EDIT I did some Googling and I think you need to use some sort of template in order to make the trigger work.
例如:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/ae2dbfb7-5dd6-4352-bfa1-53634289329d
http://www.thejoyofcode.com/Help_Why_cant_I_use_DataTriggers_with_controls_in_WPF.aspx
这篇关于WPF 触发器绑定到 MVVM 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文