Column Header Style

Hi I have the following problem when trying to create a style and apply it to the DataGrid Header get the following error

DependencyProperty.UnsetValue} 'is not a valid value for property' ColumnHeaderStyle '. "

He failed to see that this is so, if anyone can give me an idea I would appreciate leave the grid code and style. -

  <!-- ************** DATAGRID ************ -->
<Style x:Key="DataGridFloatingWindow" TargetType="{x:Type DataGrid}">
    <Setter Property="AutoGenerateColumns" Value="False" />
    <Setter Property="CanUserAddRows" Value="False" />
    <Setter Property="CanUserReorderColumns" Value="False" />
    <Setter Property="CanUserResizeColumns" Value="False" />
    <Setter Property="CanUserResizeRows" Value="False" />
    <Setter Property="CanUserSortColumns" Value="False" />
    <Setter Property="IsReadOnly" Value="True" />
    <Setter Property="SelectionUnit" Value="FullRow" />
    <Setter Property="SelectionMode" Value="Extended" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Background" Value="#fcfcfc" />
    <Setter Property="GridLinesVisibility" Value="Horizontal" />
    <Setter Property="VerticalGridLinesBrush" Value="Transparent" />
    <!--<Setter Property="HorizontalGridLinesBrush"/>-->
    <Setter Property="ColumnHeaderStyle" Value="{StaticResource DataGridHeaderFloatingWindow}" >

        <!--<Setter.Value>
            <LinearGradientBrush StartPoint="0,0" EndPoint="3,0" MappingMode="Absolute" SpreadMethod="Repeat">
                <GradientStop Offset="0" Color="#dedede"/>
                <GradientStop Offset="0.5" Color="#dedede"/>
                <GradientStop Offset="0.5" Color="Transparent"/>
                <GradientStop Offset="1" Color="Transparent"/>
            </LinearGradientBrush>
        </Setter.Value>-->
    </Setter>



    <Setter Property="RowStyle">
        <Setter.Value>
            <Style TargetType="{x:Type DataGridRow}">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="true">
                        <Setter Property="Background" Value="#dcdcdc" />
                        <Setter Property="BorderThickness" Value="0.50"></Setter>
                        <Setter Property="BorderBrush" Value="#787676"></Setter>
                        <Setter Property="Foreground" Value="#6e6e6e"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Setter.Value>
    </Setter>


    <Setter Property="CellStyle">
        <Setter.Value>
            <Style TargetType="{x:Type DataGridCell}">
                <Setter Property="FontFamily" Value="{DynamicResource KozukaGothicPro}" />
                <Setter Property="FontSize" Value="10" />
                <Setter Property="Foreground" Value="#6e6e6e" />
                <Setter Property="FontWeight" Value="Medium" />
                <Setter Property="Padding" Value="10 5 10 7" />

                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="true">
                        <Setter Property="BorderThickness" Value="0"></Setter>
                        <Setter Property="Background" Value="#dcdcdc" />
                        <Setter Property="Foreground" Value="#040404"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Setter.Value>
    </Setter>
</Style>


<Style x:Key="DataGridHeaderFloatingWindow" 
       TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="MinWidth" Value="0" />
    <Setter Property="MinHeight" Value="28" />
    <Setter Property="Foreground" Value="White" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <ContentPresenter Margin="6,3,6,3" VerticalAlignment="Center" />
                    <Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill" 
                          Grid.Column="1" Width="8" Height="6" Fill="Red" Margin="0,0,8,0" 
                          VerticalAlignment="Center" RenderTransformOrigin="0.5,0.4" />
                </Grid>
                <ControlTemplate.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="True" />
                            <Condition Property="SortDirection" Value="{x:Null}" />
                        </MultiTrigger.Conditions>
                    </MultiTrigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="true" />
                            <Condition Property="SortDirection" Value="{x:Null}" />
                        </MultiTrigger.Conditions>
                    </MultiTrigger>

                    <Trigger Property="SortDirection" Value="Ascending">
                        <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        <Setter TargetName="SortArrow" Property="RenderTransform">
                            <Setter.Value>
                                <RotateTransform Angle="180" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="SortDirection" Value="Descending">
                        <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

 <DataGrid x:Name="GeographicZones" Style="{DynamicResource DataGridFloatingWindow}" >
                    <DataGrid.Columns>
                        <DataGridTemplateColumn >
                            <DataGridTemplateColumn.Header>
                                <CheckBox x:Name="CheckBoxSelectAll"></CheckBox>
                            </DataGridTemplateColumn.Header>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Source={x:Reference CheckBoxSelectAll}, Path=IsChecked, Mode=OneWay}"></CheckBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTemplateColumn>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Button Style="{StaticResource GridEditButtonStyle}" Content="{StaticResource GridEditDetailNormal}"></Button>
                                        <Button Style="{StaticResource GridViewButtonStyle}" Content="{StaticResource GridViewDetailNormal}"></Button>
                                    </Grid>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Header="{DynamicResource FW_General_Name}" Binding="{Binding Path=Name}" />
                        <DataGridTextColumn Header="{DynamicResource FW_General_Code}" Binding="{Binding Path=Code}" />
                        <DataGridTemplateColumn Header="{DynamicResource FW_General_Enabled}">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <ContentPresenter Content="{StaticResource GridViewEnabled}" Style="{StaticResource DataGridIconOnEnabled}" />
                                        <ContentPresenter Content="{StaticResource GridViewDisabled}" Style="{StaticResource DataGridIconOnDisabled}" />
                                    </Grid>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>

Answers


Replace StaticResource in this line with DynamicResource -

<Setter Property="ColumnHeaderStyle"
        Value="{StaticResource DataGridHeaderFloatingWindow}" >

to

<Setter Property="ColumnHeaderStyle"
        Value="{DynamicResource DataGridHeaderFloatingWindow}" >

Or,move the style DataGridHeaderFloatingWindow above DataGridFloatingWindow in your xaml so as to resolve the reference.

With DynamicResource the reference will be resolved at runtime when the dataGrid will be loaded. Whereas, for StaticResource reference need to be resolved at loading of xaml, so any StaticResource used in the xaml should be defined above its usage.


Need Your Help

How to match timestamps of different formats

c# list timestamp

I have two lists that store timestamps within them. However the format in both lists is different, ListA stores it as 07/27/2015 18:10:14 while ListB stores it as 12:33. My objective is to search b...

How do I send a SNMP trap to multiple managers using snmp4j?

snmp snmp4j

Need to forward the snmp trap to multiple managers.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.