A
A
Arseniy2014-06-01 15:17:06
WPF
Arseniy, 2014-06-01 15:17:06

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:
a77d618d48354f7fb65804244d60f343.jpg
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

1 answer(s)
A
Arseniy, 2014-06-01
@Trytge

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 question

Ask a Question

731 491 924 answers to any question