3

Making a separate question, related to comments on the answer to WPF 4: What happened to DataGridColumnHeader?

It appears I can use DataGridHeaderBorder in a UserControl, stand-alone in a ResourceDictionary, but not in a Style's setter of a Template.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    >

    <!-- Works -->
    <DataTemplate x:Key="yomama">
        <DataGridColumnHeader />
    </DataTemplate>

    <!-- Compile Error: error MC3074: The tag 'DataGridHeaderBorder' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'. -->
    <Style x:Key="{x:Type DataGridRowHeader}"
        TargetType="{x:Type DataGridRowHeader}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                    <Grid>
                        <DataGridHeaderBorder></DataGridHeaderBorder>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

I can get it to work if I use xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit", even though I'm not referencing WPFToolkit in the project. I've verified I'm set to .NET4 and referencing PresentationFramework v4.

Thanks for helping me remove the dg: hack.

Community
  • 1
  • 1
Thomas
  • 3,348
  • 4
  • 35
  • 49
  • Submitted to MS: https://connect.microsoft.com/VisualStudio/feedback/details/584894 Vote up if you get a chance – Thomas Aug 09 '10 at 20:31
  • 4
    @Tom. This works for me if I with xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" HTH – Berryl Aug 12 '10 at 21:50
  • @Berryl, thanks, but I shouldn't need to reference PresentationFramework.Aero, should I? – Thomas Aug 13 '10 at 18:37
  • Heck no!! But it seemed marginally less obscure that a toolkit reference that doesn't exist. BTW, when I went to up vote the bug, the link you posted gives a most unhelpful error if you aren't registered for connect, even if MSFT otherwise knows who you are (minor PITA). Cheers – Berryl Aug 13 '10 at 19:17
  • Thanks for the Themes solution, for some reason the dg: thing isn't working on my laptop. – Thomas Aug 14 '10 at 20:09

3 Answers3

10

Try:

xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
Berryl
  • 12,471
  • 22
  • 98
  • 182
2

You can also try this.In this case to change the foreground of the header.

<Style x:Key="Consulta_Grilla_HeaderStyle" 
       TargetType="{x:Type DataGridColumnHeader}">
    <Style.Resources>
        <Style TargetType="{x:Type Grid}" >
            <Setter Property="TextBlock.Foreground" Value="Yellow"/>      
        </Style>
    </Style.Resources>
</Style>
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
Nicolas
  • 29
  • 1
-1

Add PresentationFramework.Aero.dll in reference of your project.