在 WPF 中选中/取消选中 StoryBoard 中的 ToggleButton
我有一个展开/折叠某些 StackPanel
的动画,在窗口中,有一些 ToggleButton
在折叠 StackPanel
时必须取消选中。我有这样的动画:
<Storyboard x:Key="cmdUnchecked">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StackPanel1" Storyboard.TargetProperty="(FrameworkElement.Height)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="37"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
这隐藏了 StackPanel,但我需要从其他事件中取消选中 ToggleButton。
是否可以取消选中此 StoryBoard
中的 ToggleButton
?
如果是这样,我是否需要验证它是否已选中/未选中?
I have an animation that expand / collapse some StackPanel
s, in the window there are some ToggleButton
s that must be unchecked when the StackPanel
is collapsed. I have the animation like this:
<Storyboard x:Key="cmdUnchecked">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StackPanel1" Storyboard.TargetProperty="(FrameworkElement.Height)">
<SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="37"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
This hides the StackPanel
, but I need to uncheck the ToggleButton
from other events.
Is it possible to uncheck the ToggleButton
From this StoryBoard
?
An if so, do I need to verify if it's already checked / unchecked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像这样使用 ObjectAnimationUsingKeyFrames:
您不需要检查它是否已被检查,因为当它已经为 false 时将其设置为 false 应该不会有副作用。
You can use an ObjectAnimationUsingKeyFrames like so:
You should not need to check if it's already checked since setting it to false when it's already false should have no side effects.
您应该使用
BooleanAnimations
来为布尔值设置动画:您可以将
DoubleAnimations
放在ToggleButton.Triggers
中作为EventTriggers
上 < code>RoatedEventsChecked
和Unckecked
,然后只需使用BooleanAnimation
和ToggleButton
选中/取消选中切换按钮> 将自动运行双动画来改变 stackpanel 的高度You should use
BooleanAnimations
to animate Boolean values:You can put your
DoubleAnimations
inToggleButton.Triggers
asEventTriggers
onRoutedEvents
Checked
andUnckecked
, then just check/unckeck the toggle button withBooleanAnimation
andToggleButton
will automatically run the double animations to change height of stackpanel