Use animation to change window size in WPF

∥☆過路亽.° 提交于 2019-12-24 02:50:08

问题


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.

I haven't used Storyboard - DoubleAnimation so if anyone can give me some tips I would appreciate it.


回答1:


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>


来源:https://stackoverflow.com/questions/19554073/use-animation-to-change-window-size-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!