WPF程序。StackPanel中加入多个自定义控件Item。想用动画把其中一个Item的高度调至0,运行时出错。求指导
2个回答
展开全部
我做了个demo 在一个StackPanel 里放了n个button做实验。你参考下吧。
在Window.Resources里加
<Storyboard x:Key="Storyboard1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="btn">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
在Window.Triggers里加
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</EventTrigger>
XAML代码:
<StackPanel Orientation="Horizontal">
<Button Width="50" Height="50"/>
<Button Width="50" Height="50"/>
<Button x:Name="btn" Width="50" Height="50"/>
<Button Width="50" Height="50"/>
<Button Width="50" Height="50"/>
</StackPanel>
在Window.Resources里加
<Storyboard x:Key="Storyboard1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="btn">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
在Window.Triggers里加
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</EventTrigger>
XAML代码:
<StackPanel Orientation="Horizontal">
<Button Width="50" Height="50"/>
<Button Width="50" Height="50"/>
<Button x:Name="btn" Width="50" Height="50"/>
<Button Width="50" Height="50"/>
<Button Width="50" Height="50"/>
</StackPanel>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询