2012-12-10 72 views
1

带有安装和引用的WPF工具包的vS 2008。 在Window1.xaml我加入这一行:DataGrid样式

xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" 

它运行,网格显示的数据,直到我试图风格电网。尝试应用以文本为中心的样式时出现错误。该错误涉及App.xaml,并且是:

该类型引用无法找到名为'DataGridCell'的公共类型。 9号线位置75.

我的App.xaml

<Application x:Class="DataGridStyles.App" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"       
StartupUri="Window1.xaml"> 
<Application.Resources> 

    <Style x:Key="CenterCellStyle" TargetType="{x:Type DataGridCell}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type DataGridCell}"> 
        <Grid Background="{TemplateBinding Background}"> 
         <ContentPresenter HorizontalAlignment="Center" 
            VerticalAlignment="Center"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
     <Style.Triggers> 
      <Trigger Property="IsSelected" Value="True"> 
       <Setter Property="Background" Value="Transparent" /> 
       <Setter Property="BorderBrush" Value="Transparent" /> 
       <Setter Property="Foreground" Value="Black" /> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 

</Application.Resources> 
</Application> 
+0

我遇到同样的问题来了,请张贴的解决方案,如果你找到了一个。 –

回答

0

如果DataGrid的WPF工具包的一部分,你需要添加命名空间,你的App.xaml中太(xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit")。

然后,只需改变你TargetType="{x:Type DataGridCell}"TargetType="{x:Type my:DataGridCell}"