Societymedia
Societymedia

Reputation: 125

Style not being applied to Datagrid Header in WPF ... Resource Issue

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

Upvotes: 0

Views: 1578

Answers (2)

Craig
Craig

Reputation: 1

I have had the same issue, after much experimentation I found the Text Block Style was over-riding the Grid Column Header Style, but only when specified as an Application resource, not when specified as a Window Resource.

Upvotes: 0

user112889
user112889

Reputation: 805

Try this to include the ResourceDictionary:

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

Upvotes: 1

Related Questions