我有一个资源字典,其中包含一个数据网格样式和该数据网格样式内的样式。
当我运行我的应用程序时,我收到了资源未找到异常。如果我将该样式放在资源词典根目录上,它可以工作。但是我想让
如何在不将其移动到资源字典根目录的情况下,在我的XAML中使用
提前感谢。
<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
保留在CatalogDataGrid
的<Style.Resources>
中。如何在不将其移动到资源字典根目录的情况下,在我的XAML中使用
RightAlignedDataGridCell
?提前感谢。