开发者

Explicit DataGrid CellStyle Setter is overridden by an implicit cellstyle in the same context?

开发者 https://www.devze.com 2023-01-17 20:50 出处:网络
I have a weird issue with the DataGrid in WPFToolkit (.NET 3.5) and the built in version in .NET 4.0:

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 ?

0

精彩评论

暂无评论...
验证码 换一张
取 消