Home Forums WPF controls Xceed DataGrid for WPF Images in cell based on boolean column in bound grid

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22548 |

    I have a datagrid bound to a datatable. What I am trying to do is display one image in the column if the value is true or another one if the value is false. What is the best way to accomplish this in the datagrid?

    Imported from legacy forums. Posted by Rick (had 3594 views)

    Xceed Support
    Member
    Post count: 5658

    What you need to do is affect a DataTemplate to the CellContentTemplate property of the desired column. In the template, place a trigger to set the image accordingly.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 212 views)

    User (Old forums)
    Member
    Post count: 23064

    Ok here is what I have that isn’t working.

    DataTemplate:

    <DataTemplate x:Key=”InUseDataTemplate”>
    <Grid>
    <Image x:Name=”InUseImage” Source=”/images/Locked48.png”
    Height=”20″
    VerticalAlignment=”Top”
    Margin=”0″/>
    </Grid>
    <DataTemplate.Triggers>
    <DataTrigger Binding=”{Binding InUse}” Value=”False”>
    <DataTrigger.Setters>
    <Setter TargetName=”InUseImage” Property=”Visibility” Value=”Hidden” />
    </DataTrigger.Setters>
    </DataTrigger>
    </DataTemplate.Triggers>
    </DataTemplate>

    Column definition:

    <xcdg:Column FieldName=”InUse”
    Title=”In Use”
    VisiblePosition=”7″ Width=”40″
    CellContentTemplate=”{StaticResource InUseDataTemplate}” />

    My table field is “InUse” and is a boolean. I know it has to be something obvious. Any help would be appreciated.

    Imported from legacy forums. Posted by Rick (had 403 views)

    Xceed Support
    Member
    Post count: 5658

    in the DataTrigger, can you try the following:

    <DataTrigger Binding=”{Binding}” Value=”False”>

    The rest seems okay!

    Imported from legacy forums. Posted by Marcus [Xceed] (had 336 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks a lot, that worked. Is there anywhere you could recommend that might explain how that works?

    Imported from legacy forums. Posted by Rick (had 4635 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.