Theming default ElementStyle and EditingElementStyle

Mar 24, 2009 at 7:48 PM
I'm trying to style the DataGrid to fit with our company's existing WPF theme.  I've managed to style most of the DataGrid, but there doesn't seem to be a way to style the DefaultElementStyle and DefaultEditingElementStyle for all of the variations of the DataGridBoundColumn (Text, ComboBox, CheckBox, Hyperlink), other than modifying the source code.  This is necessary to provide a consistent look (same as the standard CheckBox, TextBox, ComboBox controls). 

Obviously, you could do it manually for every DataGrid on every DataGrid column:

<dg:DataGridTextColumn Header="First Name" Binding="{Binding Name}">
  <Style TargetType="TextBlock" BasedOn="{x:Static dg:DataGridTextColumn.DefaultElementStyle}">
   <Setter Property="Foreground" Value="Green"/>
  <Style TargetType="TextBox" BasedOn="{x:Static dg:DataGridTextColumn.DefaultEditingElementStyle}">
   <Setter Property="Foreground" Value="Yellow"/>

but that doesn't seem right...

Ideally, you could just do it in the same resource dictionary that we are styling the rest of the DataGrid elements.  Maybe something like:

<Style x:Key="DataGridTextColumnElementStyle" TargetType="{x:Type TextBlock}" BasedOn="{x:Static dg:DataGridTextColumn.DefaultElementStyle}">
 <Setter Property="Foreground" Value="Green"/>

<Style x:Key="DataGridTextColumnEditingElementStyle" TargetType="{x:Type TextBox}" BasedOn="{x:Static dg:DataGridTextColumn.DefaultEditingElementStyle}">
 <Setter Property="Foreground" Value="Yellow"/>

<Style x:Key="{x:Type dg:DataGridTextColumn}" TargetType="{x:Type dg:DataGridTextColumn}">
 <Setter Property="ElementStyle" Value="{StaticResource DataGridTextColumnElementStyle}"/>
 <Setter Property="EditingElementStyle" Value="{StaticResource DataGridTextColumnEditingElementStyle}"/>

But of course that doesn't work... Any ideas?

Mar 24, 2009 at 7:53 PM
Unfortunately, we don't have a solution for this. I've added this to our list of scenarios to support in a future version.