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
1385
UnboundField with Image
posted

Hi guys,

I am trying to display an image in a cell (UnboundField) of a XamDataGrid based on a value of another cell.

With a DataGrid I got it working like this:

<DataGrid Name="dataGrid" ItemsSource="{Binding}" >
    <DataGrid.Columns>
        <DataGridTemplateColumn Header="Text" Width="SizeToCells" IsReadOnly="True">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Image Source="{Binding Path=id, Converter={StaticResource IdToImageConverter}, ConverterParameter='png'}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

Could anyone help me with that in a XamDatagrid? This is my code which is not working, I guess the problem is the wrong RelativeSource in the ControlTemplate:

<UserControl.Resources>
    <local:IdToImageConverter x:Key="IdToImageConverter" />
    <Style x:Key="IconCellStyle" TargetType="{x:Type igDP:CellValuePresenter}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                    <Grid>
                        <Image Source="{Binding Path=id, Converter={StaticResource IdToImageConverter}, ConverterParameter=png, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

<igDP:XamDataGrid Name="xamDataGrid" DataSource="{Binding}" >
    <igDP:XamDataGrid.FieldLayouts>
        <igDP:FieldLayout>
            <igDP:FieldLayout.Fields>
                <igDP:UnboundField Label="Text">
                    <igDP:UnboundField.Settings>
                        <igDP:FieldSettings CellValuePresenterStyle="{StaticResource IconCellStyle}" />
                    </igDP:UnboundField.Settings>
                </igDP:UnboundField>
            </igDP:FieldLayout.Fields>
        </igDP:FieldLayout>
    </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>

Thanks a lot and kindregards!

Parents Reply Children
No Data