显式 DataGrid CellStyle Setter 被同一上下文中的隐式单元格样式覆盖?
我对 WPFToolkit (.NET 3.5) 中的 DataGrid
和 .NET 4.0 中的内置版本有一个奇怪的问题:
使用显式设置器创建键控 DataGrid
样式时对于 CellStyle
到另一个键控样式,它的工作原理与怀疑的一样。但是,当还为 DataGridCell
创建无键样式时,它将覆盖 DataGrid
样式中的显式 CellStyle
-setter。这似乎是错误的。这是设计使然还是错误?
<Window.Resources>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="Blue" />
</Style>
<Style x:Key="CellStyle1" TargetType="DataGridCell">
<Setter Property="Background" Value="Green" />
</Style>
<Style TargetType="DataGrid">
<Setter Property="Background" Value="Yellow" />
<Setter Property="CellStyle" Value="{StaticResource CellStyle1}" />
</Style>
<XmlDataProvider x:Key="xmldata" XPath="data/*">
<x:XData>
<data xmlns="">
<item1 />
<item2 />
<item3 />
</data>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<Grid>
<DataGrid ItemsSource="{Binding Source={StaticResource xmldata}}" />
</Grid>
I have a weird issue with the DataGrid
in WPFToolkit (.NET 3.5) and the built in version in .NET 4.0:
When creating a keyed DataGrid
-style with an explicit setter for CellStyle
to another keyed style it works as suspected. But when also creating an keyless style for DataGridCell
it will override the explicit CellStyle
-setter in the DataGrid
-style. This seems wrong. Is this by design or is it a bug?
<Window.Resources>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="Blue" />
</Style>
<Style x:Key="CellStyle1" TargetType="DataGridCell">
<Setter Property="Background" Value="Green" />
</Style>
<Style TargetType="DataGrid">
<Setter Property="Background" Value="Yellow" />
<Setter Property="CellStyle" Value="{StaticResource CellStyle1}" />
</Style>
<XmlDataProvider x:Key="xmldata" XPath="data/*">
<x:XData>
<data xmlns="">
<item1 />
<item2 />
<item3 />
</data>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<Grid>
<DataGrid ItemsSource="{Binding Source={StaticResource xmldata}}" />
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是有效的:
似乎
Datagrid
的无键样式比DataGridCell
的无键样式弱。这很奇怪,但这是一个有点复杂的问题:未加钥匙的母亲与未加钥匙的孩子,谁应该获胜?This works :
It seems that the un-keyed style of the
Datagrid
is weaker than the un-keyed style of theDataGridCell
. It's quite strange, but this is a bit complex question : Unkeyed mother vs Unkeyed child, who should wins ?