Question

I want to define a global setting for a XamDataGrid for my applcation, but i would like other developers to have the ability to override particular settings without overriding the entire thing. Sample xaml below:

   <igDP:FieldLayoutSettings x:Key="DefaultFieldLayoutSettings"
    HighlightAlternateRecords="True"
    FilterRecordLocation="OnTop"
    FilterUIType="LabelIcons"
    ReevaluateFiltersOnDataChange="True"
    SummaryDescriptionVisibility="Visible"
    GroupBySummaryDisplayMode="SummaryCellsAlwaysBelowDescription"
    AllowClipboardOperations="Copy"
    AllowRecordFixing="Top"
    AllowAddNew="False"
    AllowDelete="False"
    AutoFitMode="ExtendLastField"
    AutoGenerateFields="False"
    HeaderPrefixAreaDisplayMode="FieldChooserButton"
    HighlightPrimaryField="Highlight"
    FixedFieldUIType="Button"
    FixedRecordUIType="Button"
    DataRecordCellAreaStyle="{StaticResource defaultDataRecordCellArea}"
    />

    <igDP:FieldSettings x:Key="DefaultFieldSettings"
    AllowRecordFiltering="True"
    FilterClearButtonVisibility="Visible"
    FilterStringComparisonType="CaseInsensitive"
    FilterLabelIconDropDownType="MultiSelectExcelStyle"
    AllowSummaries="True"
    CellHeight="200"
    SummaryDisplayArea="BottomFixed"
    SummaryUIType="MultiSelectForNumericsOnly"
    AllowEdit="False"
    AllowFixing="Near"
    AllowGroupBy="True"
    AllowResize="True"
    />
    <Style x:Key="DefaultXamDataGridStyle" TargetType="{x:Type igDP:XamDataGrid}">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Theme" Value="Office2010Blue" />
    <Setter Property="IsNestedDataDisplayEnabled" Value="False"/>
    <Setter Property="ClipboardCellDelimiter" Value=","/>
    <Setter Property="ClipboardRecordSeparator" Value=";"/>
    <Setter Property="IsUndoEnabled" Value="True"/>
    <Setter Property="FieldLayoutSettings" Value="{StaticResource   DefaultFieldLayoutSettings}"/>
    <Setter Property="FieldSettings" Value="{StaticResource DefaultFieldSettings}"/>
 </Style>    

Actual xaml in a view.

   <igDP:XamDataGrid DataSource="{Binding Path=QueryStatuses}" Style="{StaticResource 
      DefaultXamDataGridStyle}">
            <igDP:XamDataGrid.FieldSettings>        
                <igDP:FieldSettings  CellClickAction="SelectRecord" />
            </igDP:XamDataGrid.FieldSettings>
    </igDP:XamDataGrid>

Now is there a way to only override what is explicitly defined in local fieldSetings and keep other global settings. Right now the local FieldSetting overrides the global fieldSettings, which make sense.

Was it helpful?

Solution

This won't be possible in XAML because the FieldSetings aren't derived from FrameworkElement so you can't have a style target them directly. When you set the FeildSetting in a style targeting the XamDataGrid and also where you define the XamDataGrid, the local one will always be the only one used.

A possible alternative would be to create an object that derives from FieldSettings and set the settings you want in the constructor of that object and then when using the grid use the custom FieldSettings object rather than the default one. For example:

public class CustomFieldSettings:FieldSettings
{
    public CustomFieldSettings():base()
    {
        this.CellClickAction = CellClickAction.SelectRecord;
    }
}

Then you would use this in XAML:

<igDP:XamDataGrid x:Name="XamDataGrid1">
    <igDP:XamDataGrid.FieldSettings>
        <local:CustomFieldSettings CellClickAction="EnterEditModeIfAllowed" />
    </igDP:XamDataGrid.FieldSettings>
...
</igDP:XamDataGrid>

This approach will allow you to create your customizations and edit any of the settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top