使用触发器WPF MVVM更改映像

Nat*_*n W 20 c# wpf xaml mvvm

这可能是一个没有脑子的人,但我似乎无法让它发挥作用.我有一个视图模型暴露了一个名为bool NotFound的属性我想将它绑定到一个触发器,以便当它更改我的控件上的图像更改时.

这是我用作其中一个视图模型的数据模板的xaml.

<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>
Run Code Online (Sandbox Code Playgroud)

我希望能够绑定到NotFound属性并更改图像源.

谢谢.
弥敦道

Nat*_*n W 47

这一切都很好,我想通了.

<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> 
Run Code Online (Sandbox Code Playgroud)