2

提出一个单独的问题,与对WPF 4 答案的评论有关:DataGridColumnHeader 发生了什么?

看来我可以在 UserControl 中使用 DataGridHeaderBorder,在 ResourceDictionary 中独立使用,但不能在样式的模板设置器中使用。

<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>

如果我使用 xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit",我可以让它工作,即使我没有在项目中引用 WPFToolkit。我已经验证我设置为 .NET4 并引用 PresentationFramework v4。

感谢您帮助我删除 dg: hack。

4

3 回答 3

9

尝试:

xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
于 2011-01-24T03:56:20.043 回答
2

你也可以试试这个。在这种情况下改变标题的前景。

<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>
于 2011-12-14T22:45:03.183 回答
-1

添加 PresentationFramework.Aero.dll 以引用您的项目。

于 2015-09-16T09:00:16.577 回答