在 WPF 中使用动画更改窗口大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19554073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use animation to change window size in WPF
提问by Juan Alberto
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- DoubleAnimationto give the impression that the window size is changing gradually.
我正在寻找一种调整窗口大小动画的方法,假设我有一个 Height=300 和 Width=300 的窗口,我有 2 个按钮,当我单击第一个按钮时,窗口大小必须更改为 Height=600 和Width=600 并且当我单击另一个按钮时,窗口大小必须恢复到原始大小,我可以简单地更改 Height 和 Width 属性,但我想使用类似的东西Storyboard-DoubleAnimation给人的印象是窗口大小正在逐渐改变。
I haven't used Storyboard- DoubleAnimationso if anyone can give me some tips I would appreciate it.
我没有使用过Storyboard-DoubleAnimation所以如果有人能给我一些提示,我将不胜感激。
回答by Nitin
You cannot animate two properties in parallel Below code can help you animate the Height and Width of Window named myWindow
您不能同时为两个属性设置动画 下面的代码可以帮助您为名为 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>

