欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

WPF實(shí)現(xiàn)左右移動(dòng)(晃動(dòng))動(dòng)畫效果

 更新時(shí)間:2017年12月29日 10:40:10   作者:柴米油鹽醬醋茶-  
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)左右移動(dòng)或晃動(dòng)動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了WPF實(shí)現(xiàn)左右移動(dòng)效果展示的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)現(xiàn)控件或布局的左右移動(dòng)(晃動(dòng))主要用到DoubleAnimation以及Storyboard

布局代碼為:

<Canvas>
    <Grid Width="200" Height="100" Background="MediumAquamarine" Name="GroupboxArea" Canvas.Left="100" Canvas.Top="200"/>
    <Button Content="Button" Height="25" Width="78" Click="Button_Click"/>


</Canvas>

后臺(tái)代碼為:

 private void Button_Click(object sender, RoutedEventArgs e)
    {
      DoubleAnimation DAnimation = new DoubleAnimation();
      DAnimation.From = 100;//起點(diǎn)
      DAnimation.To = 280;//終點(diǎn)
      DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//時(shí)間

      Storyboard.SetTarget(DAnimation, GroupboxArea);
      Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty));
      Storyboard story = new Storyboard();

      story.Completed += new EventHandler(story_Completed);//完成后要做的事
      //story.RepeatBehavior = RepeatBehavior.Forever;//無限次循環(huán),需要的自己加上
      story.Children.Add(DAnimation);
      story.Begin();
    }
    void story_Completed(object sender, EventArgs e)
    {
      DoubleAnimation DAnimation = new DoubleAnimation();
      DAnimation.From = 280;//起點(diǎn)
      DAnimation.To = 100;//終點(diǎn)
      DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//時(shí)間

      Storyboard.SetTarget(DAnimation, GroupboxArea);
      Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty));
      Storyboard story = new Storyboard();

      story.Completed += new EventHandler(storyCompleted);//完成后要做的事
      //story.RepeatBehavior = RepeatBehavior.Forever;//無限次循環(huán),需要的自己加上
      story.Children.Add(DAnimation);
      story.Begin();
    }

    void storyCompleted(object sender, EventArgs e)
    {
      DoubleAnimation DAnimation = new DoubleAnimation();
      DAnimation.From = 100;//起點(diǎn)
      DAnimation.To = 200;//終點(diǎn)
      DAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.5));//時(shí)間

      Storyboard.SetTarget(DAnimation, GroupboxArea);
      Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty));
      Storyboard story = new Storyboard();

      //story.Completed += new EventHandler(storyCompleted);//完成后要做的事
      //story.RepeatBehavior = RepeatBehavior.Forever;//無限次循環(huán),需要的自己加上
      story.Children.Add(DAnimation);
      story.Begin();
    }

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論