Answer the question
In order to leave comments, you need to log in
How to add an image to a GridView cell (WPF)?
Can you please tell me how to add an image to a cell, provided that the value of this cell is equal to a certain value?
I'll show you with an example:
A red icon appears if the type value is ALL, in other cases it is not.
Thanks in advance for your advice.
Answer the question
In order to leave comments, you need to log in
I'm new to WPF, it may well be that there is something simpler, but this is all that I managed to come up with. I will be glad if someone can help
<GridViewColumn>
<GridViewColumn.Header>
<TextBlock Text="type" ToolTip="Тип объединения, которое использует MySQL"></TextBlock>
</GridViewColumn.Header>
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image x:Name="Img"></Image>
<TextBlock x:Name="Txt" Text="{Binding Path=Type}"/>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=Type}" Value="ALL">
<Setter TargetName="Txt" Property="Foreground" Value="Red" />
<Setter TargetName="Img" Property="Source" Value="4.png"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question