2
votes

Here is the code of XAML:

<Page.Resources>
        <Style x:Key="cells" TargetType="GridViewColumnHeader">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="True">
                    <Setter Property="Background" Value="#FF00B9FF"></Setter>
                    <Setter Property="Foreground" Value="White"></Setter>
                    <Setter Property="BorderBrush" Value="#FF00B9FF"></Setter>
                    <Setter Property="Padding" Value="8"></Setter>
                    <Setter Property="MinWidth" Value="100"></Setter>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#FF00B9FF"></Setter>
                    <Setter Property="Foreground" Value="White"></Setter>
                    <Setter Property="BorderBrush" Value="#FF00B9FF"></Setter>
                    <Setter Property="Padding" Value="2"></Setter>
                    <Setter Property="MinWidth" Value="100"></Setter>
                </Trigger>
            </Style.Triggers>

        </Style>
    </Page.Resources>
    <Grid>
        <Label Content="Notifications" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="20"></Label>
        <ListView Background="{x:Null}" FontSize="17" Margin="0,30,0,0" ItemsSource="{Binding Notifications}" HorizontalAlignment="Center" BorderBrush="{x:Null}">
            <ListView.View>
                <GridView AllowsColumnReorder="False">
                    <GridViewColumn Header="Sl No." DisplayMemberBinding="{Binding Slno}" HeaderContainerStyle="{StaticResource cells}"></GridViewColumn>
                    <GridViewColumn Header="Message" DisplayMemberBinding="{Binding Message}" HeaderContainerStyle="{StaticResource cells}"></GridViewColumn>
                    <GridViewColumn Header="Date" DisplayMemberBinding="{Binding Date}" HeaderContainerStyle="{StaticResource cells}"></GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>

The IsEnabled trigger is fine but the IsMouseOver trigger does not work. I tried to use the ControlTemplate but there is no property for <GridViewColumn/> and returns an error Cannot convert ControlTemplate type to DataTemplate or Style.

I am trying to change the style of my Grid Header, when on MOuseOver the default template is showing.

How can i override the style?

1
Got the answer to my problem from stackoverflow.com/questions/1172534/… - harikrishnan.n0077

1 Answers

2
votes

Your trigger is working fine, its just that you are not seeing what you expect,you will need to to set the ContolTemplate within a setter such as

    <Trigger Property="IsMouseOver" Value="True">
           <Setter Property="Template">
                 <Setter.Value>
                      <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                      <Border BorderBrush="#FF00B9FF" Background="#FF00B9FF">
                             <TextBlock Padding="5,5,5,5" Text="{TemplateBinding Content}" TextAlignment="Center" />
                       </Border>
                   </ControlTemplate>
                 </Setter.Value>
            </Setter>
            <Setter Property="Padding" Value="2"></Setter>
    </Trigger>

also note that you can set the ColumnHeaderStyle once in your GridView rather than setting it multiple time for all headers, such as:

<GridView AllowsColumnReorder="False" ColumnHeaderContainerStyle="{StaticResource cells}">