Question

My first issue is that my image is not displaying, code is as follows;

<GridViewColumn Width="100" Header="Image">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <Image Width="16" Height="16" Source="Images\green_tick.jpg"/>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

The second is that I am not sure how to begin to display an image based on the variable (a bool) under the binding {Binding ExtractionCompleted}

Thanks.

Was it helpful?

Solution

You can do this via a DataTrigger.

<GridViewColumn Width="100" Header="Image">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <Image Width="16" Height="16" Source="Images\green_tick.jpg">
                <Image.Style>
                     <Style TargetType="{x:Type Image}">
                        <Setter Property="Visibility" Value="Visible" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ExtractionCompleted}" Value="True">
                                 <Setter Property="Visibility" Value="Hidden" />
                            </DataTrigger>
                        </Style.Triggers>
                     </Style>
                </Image.Style>
            </Image>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

As for your image, make sure the BuildAction is set to Resource. You can do this by checking the Properties of it.

OTHER TIPS

Try This.

XAML:

<DataTemplate x:Key="MyImageTemplate">
        <Image Source="{Binding Path=Value}" Height="20"></Image>
    </DataTemplate>

Define an unbound column:

XAML:

<dxg:GridColumn FieldName="MyTempField" CellTemplate="{StaticResource MyImageTemplate}" UnboundType="Object" />

Then comes the handling part of GridControl.CustomUnboundColumnData event to set a value:

private void grid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e)
    {

        if (e.IsGetData)
        {
            if (((NewTestData)((GridControl)sender).GetRowByListIndex(e.ListSourceRowIndex)).Number1 > 10)
                e.Value = "demo.gif";
            else
                e.Value = null;
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top