【问题标题】:WPF4 DataGridHeaderBorder in a xaml StyleXaml 样式中的 WPF4 DataGridHeaderBorder
【发布时间】:2010-07-29 17:27:49
【问题描述】:

WPF 4: What happened to DataGridColumnHeader?的答案上提出一个单独的问题,与cmets有关

看来我可以在 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。

【问题讨论】:

  • @Tom。如果我使用 xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" HTH,这对我有用
  • @Berryl,谢谢,但我不需要引用 PresentationFramework.Aero,应该吗?
  • 见鬼!但是似乎不存在的工具包引用似乎不那么晦涩难懂。顺便说一句,当我对这个错误进行投票时,如果你没有注册连接,你发布的链接会给出一个最无用的错误,即使 MSFT 知道你是谁(小 PITA)。干杯
  • 感谢主题解决方案,由于某种原因,dg: 东西在我的笔记本电脑上无法正常工作。

标签: wpf xaml wpfdatagrid wpf-4.0 datagridheaderborder


【解决方案1】:

试试:

xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"

【讨论】:

  • 不要忘记将PresentationFramework.Aero 也添加到项目的引用中。
【解决方案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>

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2011-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多