Silverlight:VisualState 动画以某种方式被覆盖

发布于 2024-08-18 19:06:21 字数 3733 浏览 5 评论 0原文

我有一个相当复杂的自定义控件,如果我向您展示所有代码,您会大吃一惊。 ;) 一般来说,它是一个显示多个控件的面​​板。您可以将其视为自定义列表框。 (请不要告诉我使用列表框,我曾经去过那里,它并不能完全满足我的需求)。

因此,我在 VisualStateManager 中设置了一些动画。发生的情况如下:

  • 当我将鼠标悬停在我的子控件之一上时,我希望触发 MouseOver 状态。确实如此。
  • 当我选择我的子控件之一时,我期望Selected状态被触发并且它确实发生了。
  • 当我选择不同的子控件时,也会触发已选择状态
  • 当我返回到我选择的第一个子控件并选择它时,Selected 状态显示为触发(通过我的代码中的调试语句),但显示 MouseOver 动画。

是否存在能够以某种方式覆盖动画的问题,或者我不知道的 MouseOver 和选定状态之间的问题?

这是我的 VSM 标记:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">       
        <VisualState x:Name="Normal">
            <Storyboard>
                <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.150000" Storyboard.TargetName="Backdrop" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="0" Value="DarkGray"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
        <VisualState x:Name="MouseOver">
            <Storyboard>
                <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.150000" Storyboard.TargetName="Backdrop" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="0" Value="Yellow"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
    <VisualStateGroup x:Name="SelectedStates">
        <VisualState x:Name="Unselected">
            <Storyboard>
                <ColorAnimationUsingKeyFrames BeginTime="0" Duration="1" Storyboard.TargetName="Backdrop" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="0" Value="Purple"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
        <VisualState x:Name="Selected">
            <Storyboard>
                <ColorAnimationUsingKeyFrames BeginTime="0" Duration="1" Storyboard.TargetName="Backdrop" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="0" Value="Green"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

这是我的 GoToState() 逻辑:

private void GoToState(bool useTransitions) { TestVariables(“GoToState 内部”);

if (_isSelected)
{
    System.Diagnostics.Debug.WriteLine(_thumbnail.ShortFileName + " firing Selected VSM");
    VisualStateManager.GoToState(this, "Selected", useTransitions);
}
else if (_wasSelected)
{
    _wasSelected = false;
    System.Diagnostics.Debug.WriteLine(_thumbnail.ShortFileName + " firing Unselected");
    VisualStateManager.GoToState(this, "Unselected", useTransitions);
}
else if (_isMouseOver)
{
    System.Diagnostics.Debug.WriteLine(_thumbnail.ShortFileName + " firing MouseOver VSM");
    VisualStateManager.GoToState(this, "MouseOver", useTransitions);
}
else
{
    System.Diagnostics.Debug.WriteLine(_thumbnail.ShortFileName + " firing Normal VSM");
    VisualStateManager.GoToState(this, "Normal", useTransitions);
}

因此

,我可以看到哪个 VisualStateManger.GoToState() 方法被触发,而对 TestingVariables() 的调用只是我用来写出条件标志的方法,我用来确定要触发哪个视觉状态。

提前致谢。

I've got a rather complicated custom control that would boggle your mind if I showed you all of the code. ;) In general it's a panel displaying multiple controls. You can think of it as a custom list box. (Please don't tell me to use a listbox, I've been there and it doesn't meet my needs completely).

So, I set some animations in a VisualStateManager. Here's what happens:

  • When I hover over one of my child controls, I expect the MouseOver state to fire. It does.
  • When I select one of my child controls I expect the Selected state to fire and it does.
  • When I select a different child control, the Selected state fires as well
  • When I go back to my first child control I selected, and select it, the Selected state is shown to fire (by debug statements in my code) but the MouseOver animation is displayed.

Is there some issue with animations able to be overridden somehow or a problem between the MouseOver and Selected states I'm not aware of?

Here's my VSM markup:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">       
        <VisualState x:Name="Normal">
            <Storyboard>
                <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.150000" Storyboard.TargetName="Backdrop" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="0" Value="DarkGray"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
        <VisualState x:Name="MouseOver">
            <Storyboard>
                <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.150000" Storyboard.TargetName="Backdrop" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="0" Value="Yellow"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
    <VisualStateGroup x:Name="SelectedStates">
        <VisualState x:Name="Unselected">
            <Storyboard>
                <ColorAnimationUsingKeyFrames BeginTime="0" Duration="1" Storyboard.TargetName="Backdrop" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="0" Value="Purple"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
        <VisualState x:Name="Selected">
            <Storyboard>
                <ColorAnimationUsingKeyFrames BeginTime="0" Duration="1" Storyboard.TargetName="Backdrop" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="0" Value="Green"/>
                </ColorAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

And here's my GoToState() logic:

private void GoToState(bool useTransitions)
{
TestingVariables("Inside GoToState");

if (_isSelected)
{
    System.Diagnostics.Debug.WriteLine(_thumbnail.ShortFileName + " firing Selected VSM");
    VisualStateManager.GoToState(this, "Selected", useTransitions);
}
else if (_wasSelected)
{
    _wasSelected = false;
    System.Diagnostics.Debug.WriteLine(_thumbnail.ShortFileName + " firing Unselected");
    VisualStateManager.GoToState(this, "Unselected", useTransitions);
}
else if (_isMouseOver)
{
    System.Diagnostics.Debug.WriteLine(_thumbnail.ShortFileName + " firing MouseOver VSM");
    VisualStateManager.GoToState(this, "MouseOver", useTransitions);
}
else
{
    System.Diagnostics.Debug.WriteLine(_thumbnail.ShortFileName + " firing Normal VSM");
    VisualStateManager.GoToState(this, "Normal", useTransitions);
}

}

So, I can see which VisualStateManger.GoToState() method is fired and the call to TestingVariables() is just a method I use to write out the conditional flags I'm using to determine which visual state to fire.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文