-1

I have a StackPanel that I style for MouseOver and PreviewMouseLeftButtonDown. In PreviewMouseLeftButtonDown I change Background color of said StackPanel. But whenever I move my mouse out the color returns to default one, I would like to have my StackPanel function as a Tab header

How can I change color of StackPanel so that It doesnt change OnMouseOut and stays that way?

     <Setter Property="Background"  Value="#2c2d2f"></Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="White"></Setter>
                </Trigger>
                <EventTrigger RoutedEvent="PreviewMouseLeftButtonDown">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetProperty="(StackPanel.Background).(SolidColorBrush.Color)" To="CadetBlue"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
Rageline
  • 79
  • 7
  • Why not use a ListBox with a custom ItemsPanelTemplate (holding your stack panel) and styling the selected item differently? Also, check out HeaderedItemsControl. – Drew Noakes Sep 22 '15 at 21:32

1 Answers1

0

I think Drew is right, and a StackPanel is not what you need. But to answer your question, your style trigger is no longer active when IsMouseOver becomes false. Perhaps MouseEnterwill solve it for you?

PScr
  • 449
  • 2
  • 11