我想在按钮单击时为堆栈面板设置动画,我单击的Button
可以动画,而StackPanel
则不可以
这在按钮ControlTemplate
<EventTrigger RoutedEvent="Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.Target="{Binding ElementName=menus}"
Storyboard.TargetProperty="Width"
From="0" To="1500"
Duration="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
这在xaml中
<StackPanel x:Name="menus" Orientation="Horizontal"
VerticalAlignment="Bottom"
HorizontalAlignment="Center"
Margin="160 0 0 120">
<Button Margin="30" Content="Open Account" Style="{StaticResource MenuButton}" />
<Button Margin="30" Content="Instant Card Printing" Style="{StaticResource MenuButton}" />
<Button Margin="30" Content="Banking Services" Style="{StaticResource MenuButton}" />
<Button Margin="30" Content="Bill Payment" Style="{StaticResource MenuButton}" />
<Button Margin="30" Content="Support" Style="{StaticResource MenuButton}" />
</StackPanel>
我希望单击该按钮后,堆栈面板从左到右进行动画处理
答案 0 :(得分:0)
我不确定您的代码是什么导致您的示例失败。 XAML中可能发生了您未发布的事件。下面是一个完整且自成一体的示例,其功能完全符合您的描述:
for each in df_list:
if 'A3' in each.loc[0]:
df_list.remove(each)
当您点击“ Clicky Button”时,<StackPanel>
<Button Content="Clicky Button" Margin="10" HorizontalAlignment="Left">
<Button.Triggers>
<EventTrigger RoutedEvent="PreviewMouseDown">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.Target="{Binding ElementName=menus}"
Storyboard.TargetProperty="Width"
From="0" To="500"
Duration="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
<StackPanel x:Name="menus" Orientation="Horizontal" Width="0"
VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button Content="Open Account" />
<Button Content="Instant Card Printing" />
<Button Content="Banking Services" />
<Button Content="Bill Payment" />
<Button Content="Support"/>
</StackPanel>
</StackPanel>
在2秒钟的时间内会增长到500的宽度。