这是我第一次使用资源字典,我创建了新的资源字典:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit">
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border x:Name="BackgroundBorder" Background="Transparent">
<ContentPresenter VerticalAlignment="Center" Margin="4,0,6,0" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush" Value="{x:Null}"/>
</Style>
在我的窗口(我想要使用该样式)中,我声明:
<ResourceDictionary x:Key="MyDictionary" Source="/AlrakizaTouch;component/MyDictionary.xaml"/>
我的问题是如何使用带有数据网格控件的样式,我试过这个:
<DataGrid x:Name="dgItemsReceipt" CellStyle="{StaticResource ResourceKey=DataGridCell}" CanUserAddRows="True" ItemsSource="{Binding ocItemsinInvoice,Mode=TwoWay}" Margin="10,-1,0,176" Width="412" AutoGenerateColumns="False" RowHeight="34" CurrentCellChanged="dgItemsReceipt_CurrentCellChanged" SelectionMode="Single" ColumnHeaderHeight="50" Foreground="#FFCFCFCF" BorderBrush="#FFE8E8E8">
<DataGrid.Columns>
</DataGrid.Columns>
</DataGrid>
但是给我这个错误“资源DataGridCell无法解决”
请帮助
答案 0 :(得分:0)
在Windows资源字典中合并字典
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/AlrakizaTouch;component/MyDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
答案 1 :(得分:0)
我对尼特的回答非常怀疑。我认为你的问题是:
CellStyle="{StaticResource ResourceKey=DataGridCell}"
而不是
CellStyle="{StaticResource ResourceKey={x:Type DataGridCell}}"
此外,您不必只合并一个字典,您可以这样做:
<Window.Resources>
<ResourceDictionary Source="/AlrakizaTouch;component/MyDictionary.xaml"/>
</Window.Resources>