views:

15

answers:

0

I have a weird issue with 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 x:Class="DataGridStyleTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<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>