Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i get an variable image in my DATAGRID depending of a certain cellvalue.


VB
<DataGrid x:Name="DG"
 CanUserAddRows="False"
 CanUserDeleteRows="False"

  removed="Transparent"
  BorderBrush="Transparent"
  GridLinesVisibility="None"
  Style="{StaticResource GrdLayout}"
  RowStyle="{DynamicResource CellLayout}" Margin="5"
  ColumnHeaderHeight="25">

    <DataGrid.Columns>
        <DataGridTemplateColumn >
            <DataGridTemplateColumn.CellTemplate >


                <DataTemplate x:Name="trFalse" >
                   <Image Source="Resources/flag_red.png" Height="20" />
                </DataTemplate>



            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>

    <DataGrid.Resources>
        <Style TargetType="{x:Type DataGridColumnHeader}">

            <Setter Property="Background" Value="SteelBlue" />
            <Setter Property="Foreground" Value="White" />
        </Style>
    </DataGrid.Resources>

</DataGrid>
Posted
Comments
Christian Amado 31-Mar-14 14:07pm    
Can you clarify you question?

1 solution

Depending on the nature of the Item Source for your grid, you can change the image source by binding it to a property / column value that changes according to the value you are interested in:

XML
<DataTemplate x:Name="trFalse" >
                       <Image Source="{Binding ImageSource}" Height="20" />
                    </DataTemplate>


Where ImageSource is the property holding the image source according to the "other" cell value.

You can also use a value converter if you have no control over the object properties.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900