wpf animation 移动控件,真有这么难找么?

来源:互联网 发布:php开发erp管理系统 编辑:程序博客网 时间:2024/06/08 12:41

找了一个小时,我觉得不是度娘的错,是国内网站抄来抄去的问题

最后在google断断续续的情况下,还是在一个英文的网站找到了答案

原文是vb.net的

http://stackoverflow.com/questions/7242457/wpf-margin-thickness


这里再次感谢曾经教我用英文关键字搜索的上司tony tang

也不难理解,用英文搜,就是英文网站嘛,用中文,哪怕只是一个符号,因为你输入法是中文,所以就搜到中文啦

我现在公司是繁体WINDOWS系统,所以在公司搜到的网站都是香港和台湾的


Storyboard result=new Storyboard();
                ThicknessAnimation animation = new ThicknessAnimation();//用ThicknessAnimation,而不是网上的DoubleAnimation,写C#多了觉得Tickness还挺情切的

                animation.From = mScrollViewer1.Margin;//mScrollViewer1是我的控件,换成需要绑定的控件即可
                //animation.EasingFunction = New PowerEase() With {.EasingMode = EasingMode.EaseInOut, .Power = 3}
                animation.To = new Thickness(mScrollViewer1.Margin.Left, mScrollViewer1.Margin.Top+10, mScrollViewer1.Margin.Right , mScrollViewer1.Margin.Bottom);
                //margin顺序        2.↑  3.
                //                       1.←     →
                //                             4.↓
                animation.Duration = new Duration(TimeSpan.FromSeconds(1.5));

                Storyboard.SetTarget(animation, mScrollViewer1);//这个代码是精华了,和网上的setTargetName不同
                //setTargetName 的作用是什么?
                //不就是为了Storyboard和控件关联,所以还不如
                //setTarget来的直接
                //其实setTargetName,程序执行时,还是通过Name字串找到Taget,在进行setTarget的,而且程序员写程序时setTargetName容易还比较容易写错
                //所以这里setTarget就好了
                //明白我的意思了吧,英文程序和国内程序的差别
                Storyboard.SetTargetProperty(animation, new PropertyPath("Margin"));//这样的写法是比较容易写错D
                result.Children.Add(animation);
                result.Begin();