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>
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.
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>
still nobody?
I'm still using the DataRecordCellAreaStyle instead of DataRecordPresenterStyle. But I still can't manage to align the content of the row to stretch so it will fille the entire row.
I tried to set the Witdh of my content with a binding to the XamDataGrid itself, but this is a few pixel too much because of the borders of the grid. Any ideas?
<ControlTemplate TargetType="{x:Type Control}" x:Key="AlternateRowStyle"> <igDP:DataRecordCellArea> <Label Content="{Binding DataItem.Omschrijving}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" Width="{Binding ElementName=myXamDataGrid, Path=ActualWidth}" Background="{DynamicResource DataRecordPresenterHeaderAreaBackground}" Foreground="White" /> </igDP:DataRecordCellArea> </ControlTemplate>