views:

258

answers:

1

Hi, I'm trying to Use a Header Style for my WPF DataGrid that sits in a UserControl. but i get this:

Cannot find resource named '{DataGridRowHeaderBackgroundStyle}'. Resource names are case sensitive. Error at object 'Microsoft.Windows.Controls.DataGridTextColumn' in markup file 'WPF;component/view/dashboardview.xaml' Line 17 Position 50.

I changed StaticResource to DynamicResource. No error but the style doesnt change.

I have the Style defined like this:

<Style  x:Key="DataGridRowHeaderBackgroundStyle"  TargetType="{x:Type Primitives:DataGridColumnHeader}">
                    <Setter Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="White" Offset="0"/>
                                <GradientStop Color="#FF4C78F0" Offset="0.983"/>
                                <GradientStop Color="#FFEDF1FD" Offset="0.422"/>
                                <GradientStop Color="#FFACC0F7" Offset="0.069"/>
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Style>

inside Window.xaml as a Resource

   <Window.Resources>
        <ResourceDictionary Source="MainDebugResources.xaml" />
    </Window.Resources>

This is in a UserControl

<data:DataGridTextColumn HeaderStyle="{StaticResource DataGridRowHeaderBackgroundStyle}"  Header="Error" Width="*"
                                           Binding="{Binding Text}" IsReadOnly="True" />

Please let me know if im doing this wrong.

Thanks

A: 

Try this to include the ResourceDictionary:

<Window.Resources>
    <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="MainDebugResources.xaml" />                
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
</Window.Resources>