WPF动画/控件位置 [英] WPF animation / Control location

查看:132
本文介绍了WPF动画/控件位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解决一个问题吗?基本上,我有一个带有网格的WPF窗口,作为网格内的布局控件,面板和2个按钮< close>.和< new>.
当用户在½秒的面板中单击关闭"按钮时,我想以这种方式对面板进行动画处理;当用户单击新建"按钮时,该面板会在关闭"按钮后面折叠并保持隐藏状态,并且保持隐藏状态,以展开所有元素以添加新记录.

问题

只要用户不更改窗口的大小,我创建的动画就可以正常工作,只要用户最大化窗口,我的动画就不会结束(在关闭"按钮的位置处)而是结束在窗口中间的某个地方.

有人可以指导我如何使动画始终在屏幕上的关闭按钮处完成吗?

附加代码:

Could someone please help me out with a problem? Basically I have a WPF window with a Grid as layout control inside grid a Panel and 2 buttons <close> and <new>.
I want to animate the panel in such a way when user click on Close button within ½ second panel collapse behind Close button and stay hidden, and similarly when user click on New button same panel animate and expands to restore all the elements to add new record.

PROBLEM

I have created animation that works fine as long as user does not change the size of window, as soon as user maximize window my animation does not finish (at Location of close button) but finishes somewhere middle of window.

Can someone guide me how can I make my animation to always finish where ever the close button is on screen?

ADDED CODE:

<Storyboard x:Key="ClosePannel">
               <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=
                                                               "(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"

                                                               Storyboard.TargetName="rect">
                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    <EasingDoubleKeyFrame KeyTime="0 .2" Value="0.168"/>
               </DoubleAnimationUsingKeyFrames>
               <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=
                                                               "(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" 

                                                               Storyboard.TargetName="rect">
                    <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                    <EasingDoubleKeyFrame KeyTime="0 .2" Value="0.135"/>
               </DoubleAnimationUsingKeyFrames>
                  <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=
                                                                  "(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" 

                                                                  Storyboard.TargetName="rect">
                        <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                        <EasingDoubleKeyFrame KeyTime="0 .2" Value="240.8"/>
                  </DoubleAnimationUsingKeyFrames>
                  <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=
                                                                  "(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" 

                                                                  Storyboard.TargetName="rect">
                       <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                       <EasingDoubleKeyFrame KeyTime="0 .2" Value="69.6"/>
                  </DoubleAnimationUsingKeyFrames>
            </Storyboard>

推荐答案

<Storyboard x:Key="ClosePannel">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=
                                           "(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"

                                           Storyboard.TargetName="rect">
				<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
				<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.168"/>
			</DoubleAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=
                                           "(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" 

                                           Storyboard.TargetName="rect">
				<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
				<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0.135"/>
			</DoubleAnimationUsingKeyFrames>
             <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=
                                            "(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" 

                                            Storyboard.TargetName="rect">
                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="240.8"/>
            </DoubleAnimationUsingKeyFrames>
             <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=
                                            "(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" 

                                            Storyboard.TargetName="rect">
             	<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
             	<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="69.6"/>
             </DoubleAnimationUsingKeyFrames>
        </Storyboard>


这篇关于WPF动画/控件位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆