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
305
Change the style of the DataRecordPresenter
posted

 

I want to give some rows a special style. I don't want to show the columns but only a label displaying some information. I prefer not to use different FieldLayouts, but only one FieldLayout.

I have styled the DataRecordPresenter and I am using a Trigger to style only the specials rows. At first this looks to work fine, but when I change my datasource by setting a new List, the styles are shown on other rows too. If I look closer, this is caused because the XamDataGrid re-uses the rows for other data, but the template is not removed. Is it possible to disable this, or are there other ways to accomplish this without multiple FieldLayouts?

Below a screenshot and the XAML. I have also attached a sample project to reproduce this.


Thanks!

 

            <igDP:XamDataGrid DataSource="{Binding CurrentCollection}">
                <igDP:XamDataGrid.FieldLayoutSettings>
                    <igDP:FieldLayoutSettings AutoGenerateFields="False">
                        <igDP:FieldLayoutSettings.DataRecordPresenterStyle>
                            <Style TargetType="{x:Type igDP:DataRecordPresenter}" BasedOn="{StaticResource {x:Type igDP:DataRecordPresenter}}">
                                <Style.Triggers>                               
                                    <DataTrigger Binding="{Binding DataItem.Description}" Value="Special">
                                        <Setter Property="TemplateGridView">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type Control}">
                                                    <igDP:DataRecordCellArea>
                                                        <Label Content="{Binding DataItem.Description}" HorizontalAlignment="Center" FontWeight="Bold"/>
                                                    </igDP:DataRecordCellArea>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </igDP:FieldLayoutSettings.DataRecordPresenterStyle>
                    </igDP:FieldLayoutSettings>
                </igDP:XamDataGrid.FieldLayoutSettings>
 
                <igDP:XamDataGrid.FieldLayouts>
                    <igDP:FieldLayout>
                        <igDP:UnboundField Binding="{Binding Code}" Label="Code"/>
                        <igDP:UnboundField Binding="{Binding Description}" Label="Description"/>
                    </igDP:FieldLayout>
                </igDP:XamDataGrid.FieldLayouts>
            </igDP:XamDataGrid>

Testapp.zip