Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
How to display Int data in Dataset as image in grid
posted

I have a dataset with a few int fields that need to display as images.  The value for these fields is 1,2,3,4, or 5.  Based on the value of that field I want to display one of five images in the cell.

Parents
  • 69686
    Suggested Answer
    posted

    Hello,

    What you need to do is to retemplate the CellValuePresenter and put an Image element inside it.

    You can assign this style to the specific field's CellValuePresenterStyle property of the FieldSettings.

    In the control template, you can create DataTriggers to bind any cell's value to the source property of the image. For example, the following code snippet changes the image depending on the Id field of the XamDataGrid.

     

    <Style x:Key="imageStyle" TargetType="{x:Type igDP:CellValuePresenter}">

                        <Setter Property="Template">

                            <Setter.Value>

                                <ControlTemplate>

                                    <Image x:Name="image" Width="20" Height="20" Source="blue.png"/>

                                    <ControlTemplate.Triggers>

                                        <DataTrigger Binding="{Binding Path=Cells[Id].Value}" Value="1">

                                            <Setter TargetName="image" Property="Source" Value="blue.png"/>

                                        </DataTrigger>

                                        <DataTrigger Binding="{Binding Path=Cells[Id].Value}" Value="2">

                                            <Setter TargetName="image" Property="Source" Value="red.png"/>

                                        </DataTrigger>

                                        <DataTrigger Binding="{Binding Path=Cells[Id].Value}" Value="3">

                                            <Setter TargetName="image" Property="Source" Value="yellow.png"/>

                                        </DataTrigger>

                                    </ControlTemplate.Triggers>

                                </ControlTemplate>

                            </Setter.Value>

                        </Setter>

                    </Style>

    Hope this helps.

     

Reply Children