WPF触发器结合MVVM财产 [英] WPF Trigger binding to MVVM property

查看:135
本文介绍了WPF触发器结合MVVM财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含我想隐藏如果在一个视图模型的一个的属性值是true图像一个DataTemplate。谁能告诉我,为什么下面的XAML不起作用?

 <图像X:NAME =IMG来源=.. \\影像\\ List_16.png保证金=0,0,5,0>
  < Image.Style>
    <样式和GT;
      < Style.Triggers>
        < D​​ataTrigger绑定={结合CurrentListHasPendingChanges}VALUE =真>
          < setter属性=Image.VisibilityVALUE =隐藏/>
        < / DataTrigger>
        < D​​ataTrigger绑定={结合CurrentListHasPendingChanges}VALUE =FALSE>
          < setter属性=Image.VisibilityVALUE =可见/>
        < / DataTrigger>
      < /Style.Triggers>
    < /样式和GT;
  < /Image.Style>
< /图像>


解决方案

这不就是

 < setter属性=能见度VALUE =隐藏/>

我假设你使用INotifyProptyChanged。

修改我做了一些谷歌搜索,我认为你需要使用某种模板,以使触发器的工作。

例如:的http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/ae2dbfb7-5dd6-4352-bfa1-53634289329d

<一个href=\"http://www.thejoyof$c$c.com/Help%5FWhy%5Fcant%5FI%5Fuse%5FDataTriggers%5Fwith%5Fcontrols%5Fin%5FWPF.aspx\" rel=\"nofollow\">http://www.thejoyof$c$c.com/Help%5FWhy%5Fcant%5FI%5Fuse%5FDataTriggers%5Fwith%5Fcontrols%5Fin%5FWPF.aspx

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="..\Images\List_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>

解决方案

isn't that

<Setter Property="Visibility" Value="Hidden" />

?

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.

eg.: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/ae2dbfb7-5dd6-4352-bfa1-53634289329d

http://www.thejoyofcode.com/Help%5FWhy%5Fcant%5FI%5Fuse%5FDataTriggers%5Fwith%5Fcontrols%5Fin%5FWPF.aspx

这篇关于WPF触发器结合MVVM财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆