You cannot do that, However in WPF you can approch this in many ways.
You can make a custom grid control with all your common properties, and use it instead of the regular DataGrid
control.
public class BaseDataGrid : DataGrid
{
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
// Set all you common properties here
SelectionUnit = DataGridSelectionUnit.Cell;
SelectionMode = DataGridSelectionMode.Single;
CellStyle = FindResource("GridEditStyle") as Style;
}
}
in your xaml
<local:BaseDataGrid x:Name="gridEditSystem"/>
<local:BaseDataGrid x:Name="gridEditPlanets"/>
You can also make a behavoir with all your common properties and attach it to the DataGrid
s you want.
public class BaseGridBehavior : Behavior<DataGrid>
{
protected override void OnAttached()
{
AssociatedObject.Initialized += AssociatedObject_Initialized;
base.OnAttached();
}
void AssociatedObject_Initialized(object sender, EventArgs e)
{
// Set all you common properties here
AssociatedObject.SelectionUnit = DataGridSelectionUnit.Cell;
AssociatedObject.SelectionMode = DataGridSelectionMode.Single;
AssociatedObject.CellStyle = AssociatedObject.FindResource("GridEditStyle") as Style;
}
}
and in xaml:
<DataGrid x:Name="gridEditSystem">
<i:Interaction.Behaviors>
<local:BaseGridBehavior/>
</i:Interaction.Behaviors>
</DataGrid>
<DataGrid x:Name="gridEditPlanets">
<i:Interaction.Behaviors>
<local:BaseGridBehavior/>
</i:Interaction.Behaviors>
</DataGrid>
This will need you to include and reference the System.Windows.Interactivity
dll
Hope this helps