Changing an item property using a DataTrigger using only XAML

I am trying to set an element property using a DataTrigger in style.

<Image x:Name="post_image1" Height="278" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding LatestFeed[1].PostImageURL}" MaxWidth="410" MaxHeight="410" Margin="0,0,50,0"> <Image.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding post_image1.Source}" Value="noimage"> <Setter Property="Image.Visibility" Value="Collapsed" /> </DataTrigger> </Style.Triggers> </Style> </Image.Style> </Image> 

I want that if the Source Value parameter is set to noimage (which I set as part of my data object), the Image Visibility property is set to Collapsed.

I think I'm close, and I'm not sure what I am missing.

0
wpf xaml
source share
1 answer

Since your style applies directly to the image, the bindings in the DataTrigger use the CurrentContext of the current image, so you can refer to the value in the same way as in the source binding.

 <Image x:Name="post_image1" Height="278" HorizontalAlignment="Left" VerticalAlignment="Top" Source="{Binding LatestFeed[1].PostImageURL}" MaxWidth="410" MaxHeight="410" Margin="0,0,50,0"> <Image.Style> <Style TargetType="{x:Type Image}"> <Style.Triggers> <DataTrigger Binding="{Binding LatestFeed[1].PostImageURL}" Value="noimage"> <Setter Property="Visibility" Value="Collapsed" /> </DataTrigger> </Style.Triggers> </Style> </Image.Style> </Image> 
+1
source share

All Articles