使用动画更改WPF中的窗口大小 [英] Use animation to change window size in WPF
问题描述
我正在寻找一种动画方法来调整窗口的大小,可以说我有一个具有Height = 300和Width = 300的窗口,我有2个按钮,当我单击第一个按钮时,窗口大小必须更改为Height = 600和Width = 600,当我单击另一个按钮时,窗口大小必须恢复为原始大小,那么我可以简单地通过更改Height和Width属性来做到这一点,但是我想使用类似故事板
- DoubleAnimation
给人的印象是窗口大小在逐渐变化。
I am looking a way to animate the resizing of a window, lets say that I have a window with Height=300 and Width=300, I have 2 buttons, when I click the first button the window size must change to Height=600 and Width=600 and when I click the other button the window size must back to the original size, well I can do this simply changing the Height and Width properties, but I would like to use something like Storyboard
- DoubleAnimation
to give the impression that the window size is changing gradually.
我没有使用 Storyboard
- DoubleAnimation
,所以如果有人可以给我一些提示,我将不胜感激。
I haven't used Storyboard
- DoubleAnimation
so if anyone can give me some tips I would appreciate it.
推荐答案
不能并行设置两个属性的动画下面的代码可以帮助您设置名为myWindow的Window的高度和宽度的动画
You cannot animate two properties in parallel Below code can help you animate the Height and Width of Window named myWindow
<Button Content="Click">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard >
<Storyboard RepeatBehavior="Forever" AutoReverse="False">
<DoubleAnimation Storyboard.TargetName="myWindow"
Storyboard.TargetProperty = "(Window.Height)"
To="300" Duration="0:0:5"/>
<Storyboard RepeatBehavior="Forever" AutoReverse="False">
<DoubleAnimation Storyboard.TargetName="myWindow"
Storyboard.TargetProperty = "(Window.Width)"
To="300" Duration="0:0:5"/>
</Storyboard>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
这篇关于使用动画更改WPF中的窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!