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="Yello开发者_开发问答w" />
<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>
This works :
<DataGrid ItemsSource="{Binding Source={StaticResource xmldata}}"
CellStyle="{StaticResource CellStyle1}" />
It seems that the un-keyed style of the Datagrid
is weaker than the un-keyed style of the DataGridCell
. It's quite strange, but this is a bit complex question : Unkeyed mother vs Unkeyed child, who should wins ?
精彩评论