2
私はリソースグリッドを定義しています。これは、そのリソースグリッドに定義されたデータグリッドスタイルと、そのデータグリッドスタイル内のスタイルです。リソース辞典内の<Styles.Resources>で定義されているリソースの使い方
<Style TargetType="{x:Type DataGrid}" x:Key="CatalogDataGrid">
<Style.Resources>
<Style TargetType="{x:Type DataGridCell}" x:Key="RightAlignedDataGridCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Padding="5,0" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" HorizontalAlignment="Right" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
</Style>
はその後、私のXAMLで私は私の列が右に整列するようにRightAlignedDataGridCell
を使用しようとしました。
<DataGrid... Style="{StaticResource CatalogDataGrid}">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"></DataGridTextColumn>
<DataGridTextColumn Header="Total" Binding="{Binding Total}" CellStyle="{StaticResource RightAlignedDataGridCell}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
私のアプリケーションを実行すると、リソースが見つかりませんでした例外が発生しました。私はそのスタイルをリソース辞書のルートに置いています。それは働くことができる。しかし、私はRightAlignedDataGridCell
が の中にとどまりたいと思っています。
RightAlignedDataGridCell
をXAML上でリソース辞書ルートに移動することなくどのように使用するのですか?
ありがとうございます。
私のresourcedictionaryはすでに私のxamlに含まれています。 –
x:Key = "RightAlignedDataGridCell"。あなたはこれを削除する必要があると思います。 – NVM
列が左揃えになるため、できません。 –