2012-12-10 2 views
1

vS 2008 avec la boîte à outils WPF installée et référencée. Dans le Window1.xaml j'ajouté cette ligne:Styles DataGrid

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

Il fonctionne, la grille affiche des données, jusqu'à ce que je tente de style de la grille. J'obtiens une erreur lorsque j'essaie d'appliquer un style qui centre le texte. L'erreur se réfère à App.xaml et est:

La référence de type ne trouve pas un type public nommé 'DataGridCell'. Ligne 9 Position 75.

Mon 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

je suis tombé sur le même problème, s'il vous plaît poster une solution si vous avez trouvé un. –

Répondre

0

Si la grille de données fait partie de la boîte à outils WPF, vous aurez besoin d'ajouter cet espace de noms dans votre App.xaml aussi (xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit").

Ensuite, il suffit de changer votre TargetType="{x:Type DataGridCell}" à TargetType="{x:Type my:DataGridCell}"