wpf视觉状态管理器有条件

时间:2014-06-20 19:28:23

标签: wpf animation expression-blend

通过更改鼠标悬停选定的状态来设置列表框的itemcontainerstyle样式。

有类似的东西

   <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="border">
                                            <EasingColorKeyFrame KeyTime="0" Value="#48FF5643"/>
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Unselected"/>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="border">
                                                <EasingColorKeyFrame KeyTime="0" Value="#FFFF5643"/>
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>


                                    <VisualState x:Name="SelectedUnfocused"/>
                                </VisualStateGroup>
enter code here

问题是,如果我选择了一个项目并将鼠标悬停在它上面,则状态更改为 mouseoverstate ,我想避免这样做

我也试过像

这样的控制模板多项目
   <MultiTrigger.Conditions>
          <Condition Property="IsSelected" Value="False" />
          <Condition Property="IsMouseOver" Value="False" />
   </MultiTrigger.Conditions>

但它不起作用,并且没有 IsMouseLeave 属性

希望我能清楚地解释这个问题,欢迎任何帮助

谢谢,美好的一天!

1 个答案:

答案 0 :(得分:0)

使用ListBoxItem.Background和一些Trigger更改SystemColors属性要容易得多。试试这个:

<ListBox ItemsSource="{Binding Days}">
    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFFF5643" />
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FFFF5643" />
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
            </Style.Resources>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#48FF5643" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

我觉得这些SystemColors可能无法在Windows 8或.NET 4.5上运行,但它们适用于.NET 4和Windows 7.让我知道它是否符合您的要求。


更新&gt;&gt;&gt;

问题是mouseLeave,eventtriggers上没有这样的属性

也许您应该进一步调查Trigger class?:

<Trigger Property="IsMouseOver" Value="True">
    <Trigger.EnterActions>
        <!--Performed with MouseEnter event-->
    </Trigger.EnterActions>
    <Trigger.ExitActions>
        <!--Performed with MouseLeave event-->
    </Trigger.ExitActions>
</Trigger>