WPF StackPanel OnClick

时间:2015-09-22 21:12:18

标签: c# wpf wpf-controls eventtrigger

我有一个StackPanel,我为MouseOver和PreviewMouseLeftButtonDown设置样式。在PreviewMouseLeftButtonDown中,我更改了所述StackPanel的背景颜色。但每当我移动鼠标时,颜色都会恢复为默认值,我希望将StackPanel函数作为Tab标题

如何更改StackPanel的颜色,以便它不会改变OnMouseOut并保持这种状态?

     <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>

1 个答案:

答案 0 :(得分:0)

我认为Drew是对的,StackPanel不是你需要的。但要回答您的问题,IsMouseOver变为false时,您的样式触发器不再有效。也许MouseEnter会为你解决它?