C# 选中/取消选中WPF中故事板上的切换按钮
我有一个动画,可以展开/折叠一些C# 选中/取消选中WPF中故事板上的切换按钮,c#,wpf,xaml,storyboard,togglebutton,C#,Wpf,Xaml,Storyboard,Togglebutton,我有一个动画,可以展开/折叠一些StackPanels,在窗口中有一些ToggleButtons,当StackPanel折叠时必须取消选中它们。我有这样的动画: <Storyboard x:Key="cmdUnchecked"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="StackPanel1" Storyboard.TargetProperty="(Framewo
StackPanel
s,在窗口中有一些ToggleButton
s,当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>
这会隐藏堆栈面板
,但我需要从其他事件中取消选中ToggleButton
是否可以从此情节提要
中取消选中切换按钮
如果是,我是否需要验证它是否已被选中/取消选中?您可以使用如下关键帧使用对象动画:
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="YourToggleButton" Storyboard.TargetProperty="(ToggleButton.IsChecked)">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="False" />
</ObjectAnimationUsingKeyFrames>
您不需要检查它是否已被选中,因为当它已为false时将其设置为false应该没有副作用。您应该使用
布尔动画
来设置布尔值的动画:
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="YourToggleButton" Storyboard.TargetProperty="IsChecked">
<DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0"/>
</BooleanAnimationUsingKeyFrames>
您可以将您的
双动画
放入切换按钮。触发器
作为事件触发器
在路由事件
上选中和取消选中
,然后用BooleanAnimation
选中/取消选中切换按钮,ToggleButton
将自动运行双动画以更改stackpanel的高度当未选中切换按钮时,它不会执行任何操作,选中时会抛出错误“无法将“System.Windows.Controls.Primitives.ToggleButton”上的属性“IsChecked”与“System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames”一起设置动画”“我是否做错了什么?