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
Parents
  • 27093
    posted

    Hello,

    I have been looking into your issue and you are right the XamDataGrid reuses its visual elements. What you can do is add to your style a DataTrigger that is triggered when the record is not special and apply the original template there. You can get the template from the DefaultStyles folder which is installed by default here: C:\Program Files (x86)\Infragistics\NetAdvantage 2010.3\WPF\DefaultStyles\DataPresenter\DataPresenterGeneric_Express.xaml

    Please let me know if you require any further assistance on the matter.

     

  • 305
    posted in reply to [Infragistics] Petar Monov

    Thanks for your response. I may have another solution. It works correctly when I'm styling the DataRecordCellAreaStyle instead of DataRecordPresenterStyle. Is this the way to go?

    The only problem I have now is that I can't center the Label. See below. Any suggestions?

                            <igDP:FieldLayoutSettings.DataRecordCellAreaStyle>
                                <Style TargetType="{x:Type igDP:DataRecordCellArea}" BasedOn="{StaticResource {x:Type igDP:DataRecordCellArea}}">
                                    <Style.Triggers>                               
                                        <DataTrigger Binding="{Binding DataItem.Description}" Value="Special">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type Control}">
                                                        <igDP:DataRecordCellArea>
                                                            <Label Content="{Binding DataItem.Description}" HorizontalContentAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" />
                                                        </igDP:DataRecordCellArea>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </igDP:FieldLayoutSettings.DataRecordCellAreaStyle>

     

Reply Children