Search code examples
wpfheadermouseoverexpander

WPF Expander Header Mouseover color change


I have wpf Expander control and I want change background color of Header when I do mouse over on it. Here is my control:

<Expander Margin="0" ExpandDirection="Right">
    <Expander.Header>
        <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
            <Image Source="placeholder_imageObject.png"  Stretch="Uniform" Margin="6,0,0,0" Width="36" Height="36" VerticalAlignment="Center"/>
            <ContentPresenter Content="Image" VerticalAlignment="Center" Margin="5,0,0,0"/>
            <Path Data="{StaticResource RightArrowGeometry}" Fill="Black"  Margin="14,0,0,0" VerticalAlignment="Center">
            </Path>
        </StackPanel>
    </Expander.Header>
    <Grid Margin="10,0,0,0" Background="White">
        <controls:SymbolController x:Name="dgSymbolControl">
        </controls:SymbolController>
    </Grid>
</Expander>

Pls Help thanks Sai


Solution

  • U can give your StackPanel within in your "Expander.Header" an Style with Trigger like this:

     <Style x:Key="MyCustomStackPanelStyle" TargetType="{x:Type StackPanel}">
          <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter Property="Background" Value="Red" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="False">
              <Setter Property="Background" Value="Transparent" />
            </Trigger>
          </Style.Triggers>
        </Style>