0

I've been given the task to migrate a 3.5 WPF app with WPFToolkit Datagrid to WPF 4.0 with built in datagrid.

The style for type DataGridColumnHeader is no longer applied?

<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
    <!-- Setters goes here -->
</Style>

edit: Problem was that in 4.0 you cant have a key name for default styles for a specific type, but in 3.5 you could. Solved it like this

<Style TargetType="{x:Type DataGridColumnHeader}">
    <!-- Setters goes here -->
</Style>

<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
</Style>
Anders
  • 17,306
  • 10
  • 76
  • 144
  • Maybe this will help http://stackoverflow.com/questions/3365350/wpf4-datagridheaderborder-in-a-xaml-style – Avram Tudor Jun 28 '13 at 13:34
  • Im no expert on 3.5 WPF, could you have named styles that also were default for all target types? This is not the case for 4.0 – Anders Jun 28 '13 at 13:41
  • Not sure if I understood your question correctly, but I don't think that the default styles have a resource key assigned to them if that's what you meant. – Avram Tudor Jun 28 '13 at 14:09
  • Exactly but it worked in teh 3.5 version, so this must been changed between 3.5 and 4.0 – Anders Jun 28 '13 at 14:15
  • @Anders For all versions of WPF, a type sets its `DefaultStyleKey`. Perhaps the toolkit version set it to `ColumnHeaderStyle` instead of the `typeof(DataGridColumnHeader)`. Or perhaps the `DataGrid` had a setter in its default style that was `{DynamicResource ColumnHeaderStyle}`. Other than that, I can't see how naming a `Style` would make it apply to all items of a type. – Abe Heidebrecht Jun 28 '13 at 15:39
  • All I did was to change project type from 3.5 to 4.0, remove reference to WPF Toolkit and change namespaces to get the style problem – Anders Jun 28 '13 at 15:48
  • Is there any software that can give all styles assigned to a element? Like Firebug for Firefox, I have another strange problem that I cant find the cause to. I have tried WPF inspector, but it cant detect which styles are used for a specific element – Anders Jul 01 '13 at 07:30

0 Answers0