使用WPF触发MVVM改变形象 [英] Change image using trigger WPF MVVM
本文介绍了使用WPF触发MVVM改变形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个没有智商更高,但我只是似乎无法得到它的工作。我有一个公开叫物业视图模型的布尔NOTFOUND 的我想将绑定到一个触发器,这样,当它在我的控制的变化而变化的图像。
This may be a no brainier but I just can't seem to get it to work. I have a view model that exposes a property called bool NotFound I would like to bind that to a trigger so that when it changes an image on my control changes.
这是我使用作为我的视图模型中的一个数据模板的XAML。
This is the xaml that I am using as a data template for one of my view models.
<DataTemplate DataType="{x:Type local:TabFileViewModel}">
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Margin="3,0" Source="Image\TabFile.PNG" />
<TextBlock Text="{Binding Name}" ToolTip="{Binding FullPath}"/>
</StackPanel>
</DataTemplate>
我希望能够绑定到的 NOTFOUND 的属性,并更改图像源。
I would like to be able to bind the to the NotFound property and change the image source.
谢谢。结果
内森
Thanks.
Nathan
推荐答案
这一切都很好,我想通了。
It's all good I figured it out.
<DataTemplate DataType="{x:Type local:TabFileViewModel}">
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Margin="3,0">
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding NotFound}" Value="false">
<Setter Property="Source" Value="Image\TabFile.PNG"/>
</DataTrigger>
<DataTrigger Binding="{Binding NotFound}" Value="true">
<Setter Property="Source" Value="Image\ErrorTabFile.PNG"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</DataTemplate>
这篇关于使用WPF触发MVVM改变形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文