WPF触发器结合MVVM财产

编程入门 行业动态 更新时间:2024-10-28 00:29:11
本文介绍了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。

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

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

www.thejoyof$c$c/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.: social.msdn.microsoft/Forums/en-US/wpf/thread/ae2dbfb7-5dd6-4352-bfa1-53634289329d

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

更多推荐

WPF触发器结合MVVM财产

本文发布于:2023-11-06 04:53:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   财产   WPF   MVVM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!