Note: This post was written a while back but sat in draft. I’ve published this now, but I’m not sure it’s relevant to the latest versions etc. so please bear this in mind.
I’m working on a project using the XamDataGrid. I’ve used the UltraWinGrid by Infragistics in the past but that doesn’t help at all when moving code from Windows Formds to WPF. So here’s a list of a few commonly required features and how to do them using the XamDataGrid.
Note: this post only refers to using version 12.2
Grid lines
Problem: By default there are no grid lines on the XamDataGrid.
Solution: In your ResourceDictionary (within Generic.xaml or wherever you prefer) add the following
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="BorderThickness" Value="0,0,1,1" /> <Setter Property="BorderBrush" Value="{x:Static SystemColors.ControlLightBrush}" /> </Style>
Obviously replace the BorderBrush colour with your preferred colour.
Remove the group by area
Problem: I want to remove the group by section from the XamDataGrid.
Solution: In your ResourceDictionary (within Generic.xaml or wherever you prefer) add the following
<Style x:Key="IceGrid" TargetType="igDP:XamDataGrid"> <Setter Property="GroupByAreaLocation" Value="None" /> </Style>
don’t forget to apply the style to your grid, i.e.
<dp:XamDataGrid Style="{StaticResource IceGrid}" DataSource="{Binding Details}"> <!- Your grid code --> </dp:XamDataGrid>
Column formatting
Problem: We want to change the numerical formatting for a column
Solution: We can set the EditorStyle for a field (editor doesn’t mean it will make the field editable)
<dp:XamDataGrid.FieldLayouts> <dp:FieldLayout> <dp:FieldLayout.Fields> <dp:Field Name="fee" Label="Fee" Width="80"> <dp:Field.Settings> <dp:FieldSettings> <dp:FieldSettings.EditorStyle> <Style TargetType="{x:Type editors:XamNumericEditor}"> <Setter Property="Format" Value="0.####" /> </Style> </dp:FieldSettings.EditorStyle> </dp:FieldSettings> </dp:Field.Settings> </dp:Field> </dp:FieldLayout.Fields> </dp:FieldLayout> </dp:XamDataGrid.FieldLayouts>
This code creates a field named fee and with the label Fee and the editor is set to only display decimal places if they actually exist.
As we’re defining the fields you’ll need to turn off auto generation of fields, as per
<dp:XamDataGrid.FieldLayoutSettings> <dp:FieldLayoutSettings AutoGenerateFields="False" /> </dp:XamDataGrid.FieldLayoutSettings>