从一个位置到另一个动画网格 [英] Animate Grid from one position to another

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

问题描述

我的图片和按钮的网格,我想从自动一个位置到另一个(实际上是几个空格向左)动画的运动,但它并没有奏效。我已经使用在XAML故事板和编程如下code试过,但其现在的工作。请帮助!

 公共静态无效通过MoveTo(网格目标)
    {
        Canvas.SetLeft(目标,0);        VAR顶部= Canvas.GetTop(目标);
        VAR左= Canvas.GetLeft(目标);
        TranslateTransform反=新TranslateTransform();
        target.RenderTransform =反;
        双下一页末=(双)(左 - 300);
        双newy指定=(双)上方;
        DoubleAnimation是anim1 =新DoubleAnimation是(顶部,-15,TimeSpan.FromSeconds(10));
        // DoubleAnimation是anim1 =新DoubleAnimation是(顶部,newy指定 - 顶部,TimeSpan.FromSeconds(10));        DoubleAnimation是anim2 =新DoubleAnimation是(左,下一页末 - 左边,TimeSpan.FromSeconds(10));
        anim1.AutoReverse = TRUE;
        anim1.RepeatBehavior = RepeatBehavior.Forever;
        trans.BeginAnimation(TranslateTransform.XProperty,anim1);
        trans.BeginAnimation(TranslateTransform.YProperty,anim2);
    }


解决方案

完全 TranslateTransform 为心不是好,你要.better使用thinkness动画

我劝你不使用canavas并将其更改为网格但是如果你使用canavas使用code

 私人无效Animationsss(网格GRD)
        {
            //创建一个动画
            DoubleAnimation是DA =新DoubleAnimation是();
            //从动画设置为起始位置
            //不要忘记电网集canvas.left如果妳不ü会得到错误
            da.From = Canvas.GetLeft(GRD);
            //设置网格第二位置
            da.To = -100;
            //设置持续时间
            da.Duration =新的持续时间(TimeSpan.FromSeconds(2));
            //运行动画,如果ü要停止,启动等用故事板
            grd.BeginAnimation(Canvas.LeftProperty,DA);        }

如果您使用网格code是这样的:

 私人无效动画(网格GRD)
        {
            ThicknessAnimation TA =新ThicknessAnimation();
            //你的第一个地方
            ta.From = grd.Margin;
            //这个从左侧搬过来网格1000
            //你可以使用-1000移动到左侧
            ta.To =新厚度(1000,0,0,0);
            //时间动画playes
            ta.Duration =新的持续时间(TimeSpan.FromSeconds(10));
            //不需要用故事板,但如果你想暂停,停止等用故事板
            grd.BeginAnimation(Grid.MarginProperty,TA);
        }

您可以使用不透明度动画淡出网格...它显示出良好的举动是否和褪色!

 私人无效Animationsss(网格GRD)
        {
            DoubleAnimation是DA =新DoubleAnimation是(1,0,新的持续时间(TimeSpan.FromSeconds(2)));
            grd.BeginAnimation(Grid.OpacityProperty,DA);
        }

如果心不是任何理由U可以改变canavas电网,也更好地使用 TranslateTransform 作为调整象下面这样code code控制调整控制,如果鼠标在里面输入:

 私人无效grid1_MouseEnter(对象发件人,MouseEventArgs E)
        {
            //首先它的正常大小
            ScaleTransform ST =新ScaleTransform(1,1);
            //动画尺寸1.25 persent实际大小
            DoubleAnimation是DA =新DoubleAnimation是(1,1.25,新的持续时间(TimeSpan.FromSeconds(2)));
            //设置变换控制
            grid1.RenderTransform = ST;
            //现在动画变换从Y和X
            st.BeginAnimation(ScaleTransform.ScaleXProperty,DA);
            st.BeginAnimation(ScaleTransform.ScaleYProperty,DA);
        }

如果您动画宽度或高度不喜欢规模同样的工作变换:)

希望我可以帮助你... ...:))

我请假评论请

I have a grid of images and buttons, and I want to animate motion from one position to another (actually a few spaces to the left) automatically, but it hasn't worked. I've tried using a storyboard in xaml and programatically as in the code below, but its now working. Please help!!!

    public static void MoveTo(Grid target)
    {
        Canvas.SetLeft(target, 0);

        var top = Canvas.GetTop(target);
        var left = Canvas.GetLeft(target);
        TranslateTransform trans = new TranslateTransform();
        target.RenderTransform = trans;
        double newX = (double)(left - 300);
        double newY = (double)top;
        DoubleAnimation anim1 = new DoubleAnimation(top, -15, TimeSpan.FromSeconds(10));
        //DoubleAnimation anim1 = new DoubleAnimation(top, newY - top, TimeSpan.FromSeconds(10));

        DoubleAnimation anim2 = new DoubleAnimation(left, newX - left, TimeSpan.FromSeconds(10));
        anim1.AutoReverse = true;
        anim1.RepeatBehavior = RepeatBehavior.Forever;
        trans.BeginAnimation(TranslateTransform.XProperty, anim1);
        trans.BeginAnimation(TranslateTransform.YProperty, anim2);
    }

解决方案

totally TranslateTransform isnt good for that you want .better to use thinkness animation

i advise you dont use canavas and change it to grid but if you use canavas use this code

 private void Animationsss(Grid grd)
        {
            //create an animation
            DoubleAnimation da = new DoubleAnimation();
            //set from animation to start position 
            //dont forget set canvas.left for grid if u dont u will get error
            da.From = Canvas.GetLeft(grd);
            //set second position of grid
            da.To = -100;
            //set duration
            da.Duration = new Duration(TimeSpan.FromSeconds(2));
            //run animation if u want stop ,start etc use story board
            grd.BeginAnimation(Canvas.LeftProperty, da);

        }

if you use grid code is this :

 private void Animation(Grid grd)
        {
            ThicknessAnimation ta = new ThicknessAnimation();
            //your first place
            ta.From = grd.Margin;
            //this move your grid 1000 over from left side
            //you can use -1000 to move to left side
            ta.To = new Thickness(1000, 0, 0, 0);
            //time the animation playes
            ta.Duration = new Duration(TimeSpan.FromSeconds(10));
            //dont need to use story board but if you want pause,stop etc use story board
            grd.BeginAnimation(Grid.MarginProperty, ta);
        }

you can use opacity animation for fade your grid ... it show good if move and fade !

    private void Animationsss(Grid grd)
        {
            DoubleAnimation da = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(2)));
            grd.BeginAnimation(Grid.OpacityProperty, da);
        }

if there isnt any reason u can change canavas to grid and also better use TranslateTransform for resize controls like code below this code resize control if mouse enter in it :

private void grid1_MouseEnter(object sender, MouseEventArgs e)
        {
            //at first its normal size
            ScaleTransform st = new ScaleTransform(1, 1);
            //animation size to 1.25 persent of real size
            DoubleAnimation da = new  DoubleAnimation(1,1.25, new Duration(TimeSpan.FromSeconds(2)));
            //set transform to control
            grid1.RenderTransform = st;
            //animation transform now From Y And X
            st.BeginAnimation(ScaleTransform.ScaleXProperty, da);
            st.BeginAnimation(ScaleTransform.ScaleYProperty, da);
        }

if you animation for width or height do same work like scale transform :)

hope i can help you ...:))

leave comment for me please

这篇关于从一个位置到另一个动画网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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