I need to centralize my FieldLayoutSettings and FieldSettings objects for all the grids in my app. I created a new grid that inherits from your grid and I was setting the default values in the constructor. But as soon as I override any settings in a xaml file, it basically creates a whole new settings object again overwriting the aleady existing one with all my default settings.
I tried creating a style for MY grid but then nothing renders. I tried basing it on your grid but then it won't run.
How can i create ONE central grid that I can easily reuse over and over again?
This is what MY grid's style looked like:
<Style TargetType="{x:Type local:DataGrid}" BasedOn="{StaticResource XamDataGrid}">
<Setter Property="FieldLayoutSettings">
<Setter.Value>
<igDP:FieldLayoutSettings AutoGenerateFields="False" />
</Setter.Value>
</Setter>
<Setter Property="FieldSettings">
<igDP:FieldSettings AllowEdit="False" CellClickAction="SelectRecord" />
</Style>
Hello,
This is because of the Depencency Property Value Precedence. A Style's setter does not have enough precedence to set change the value of a property if it is set locally (as you are doing in the xaml or procedural code). That is why the style's settings are not getting applied to the XamDataGrids.
What you could do is to keep the FieldSettings or FieldLayoutSettings as resources in the Application and apply them in the Loaded event of the XamDataGrid. You could also create some logic to check which properties are set locally and which in the resource objects so that they are not overridden.