视觉状态淡入和淡出?
目前,我定义了一组淡入路径的视觉状态,这是一个示例:
<VisualState x:Name="MyPathFadeIn">
<Storyboard>
<ColorAnimation Storyboard.TargetName="MyPath" Storyboard.TargetProperty="(Path.Fill).(SolidColorBrush.Color)" From="#00000000" To="Red" Duration="0:0:1.5" />
</Storyboard>
</VisualState>
现在我想知道,如果我从代码隐藏更改当前的视觉状态,是否有办法自动调用某种淡出状态?
Currently I have a set of visual states defined which fade in paths, here's an example:
<VisualState x:Name="MyPathFadeIn">
<Storyboard>
<ColorAnimation Storyboard.TargetName="MyPath" Storyboard.TargetProperty="(Path.Fill).(SolidColorBrush.Color)" From="#00000000" To="Red" Duration="0:0:1.5" />
</Storyboard>
</VisualState>
Now I was wondering, is there a way to automatically call some sort of fade out state if I change the current visual state from codebehind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
视觉状态都是关于状态的!在后面的代码中,您可以通过 VisualStateManager.GoToState 方法将控件设置为状态。因此,如果您想“调用”某个淡出状态,只需将控件设置为该状态即可!
Visual states are all about state! In your code behind you can set your control to a state via the
VisualStateManager.GoToState
method. So, if you want to 'call' some fade-out state, just set the control to that state!我不确定这是否有帮助,但是当您使用
ColorAnimation
时,我很确定您不必设置ColorAnimation.From
属性。如果您未设置它,则到视觉状态的过渡应从当前设置的颜色开始。因此,如果您仅使用 ColorAnimation.To 属性定义情节提要,则可能有助于显式声明所有内容?
或者,您始终可以使用自己的子类扩展 VisualStateManger。当收到新的状态更改时将所有其他
VisualStateGroups
设置为“关闭”?I'm not sure if this helps, but when you're using a
ColorAnimation
I'm quite sure you don't have to set theColorAnimation.From
property. If you leave it unset, then the Transition to the visual state should start from the colour that it is currently set as.As such, if you define the storyboards with just
ColorAnimation.To
properties, it may help in having to explicitly declare everything?Alternatively, you could always extend the
VisualStateManger
with your own subclass. One that sets all the otherVisualStateGroups
to 'Off' when it receives a new state change?