1

WPF ツールキットがインストールされ参照されている vS 2008。Window1.xaml に次の行を追加しました。

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

1 に答える 1

0

データグリッドが WPF ツールキットの一部である場合は、その名前空間を App.xaml にも追加する必要があります ( xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit")。

次に、に変更するだけTargetType="{x:Type DataGridCell}"ですTargetType="{x:Type my:DataGridCell}"

于 2012-12-10T23:17:25.523 に答える