Unable to apply styles defined in Application.Resources to DataGrid

Jun 30, 2009 at 8:20 PM

 

I must be missing something blindingly obvious because I cannot get this to work.  I have a <Style> section under <Application.Resources> like so:

<Application.Resources>

  <Style TargetType="{x:Type wpfToolkit:DataGrid}">

    <Setter Property="FontFamily" Value="Times New Roman" />

    <Setter Property="FontSize" Value="16" />

  </Style>

</Application.Resources>

 

However this does not get applied to windows where the datagrid appears.  If I explicitly set these properties at the point where the datagrid is defined in the XAML, everthing works fine.  That is, this works:

<wpfToolkit:DataGrid .... FontSize="16" FontFamily="Times New Roman" />

However my datagrid appears in many windows in my application and I wanted all of them to have a common appearance which is kinda the point behind Application-wide resources but I can't seem to get it to work!  What am I doing wrong?

 

Jun 30, 2009 at 9:02 PM

 

Believe it or not, the following made it work:

<Application.Resources>

  <Style TargetType="{x:Type wpfToolkit:DataGrid}">

    <Setter Property="FontFamily" Value="Times New Roman" />

    <Setter Property="FontSize" Value="16" />

  </Style>

  <Style TargetType="{x:Type Button}" />

</Application.Resources>

Notice I simply had to add an empty style targeting Buttons.  The TargetType is immaterial -- any empty style element will do.  I can't understand what one has to do with the other.