WPF游戏摘记--地图编辑器(3)

知识点一:storyboard创建动画

storyboard = new Storyboard();

            //创建X轴方向动画

            DoubleAnimation doubleAnimation = new DoubleAnimation(

              Canvas.GetLeft(Spirit),

              p.X,

              new Duration(TimeSpan.FromSeconds(1))

            );

            Storyboard.SetTarget(doubleAnimation, Spirit);

            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Left)"));

            storyboard.Children.Add(doubleAnimation);

            //创建Y轴方向动画

            doubleAnimation = new DoubleAnimation(

              Canvas.GetTop(Spirit),

              p.Y,

              new Duration(TimeSpan.FromSeconds(1))

            );

            Storyboard.SetTarget(doubleAnimation, Spirit);

            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Top)"));

            storyboard.Children.Add(doubleAnimation);

            //将动画动态加载进资源内

            if (!Resources.Contains("rectAnimation")) {

                Resources.Add("rectAnimation", storyboard);

            }

            //动画播放

            storyboard.Begin();

  1. 实例化一个DoubleAnimation,设置他指定的持续时间和从指定的初始值运动到目标值;
  2. 设置动画目标;
  3. 设置动画目标参数
  4. 动画开始

知识点二:动画完成判断

 storyboard.GetCurrentTime() == TimeSpan.FromSeconds(1)

这个应该和上一个一起看才是,原来就是给动画设置运动时间为1s,这里查看当前动画持续时间是否为1s。简单吧,还是那句话,有些东西懂了就很简单,不懂,就很难了。

知识点三:在WPF中的添加WinForm控件

1)  添加dll引用:需要引用WindowsFormsIntegrationl和System.Windows.Forms。

2)  如果是在xaml中使用,则需要添加类似如下的定义:

    xmlns:WinFormHost = "clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"

    xmlns:WinForm = "clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"

3)使用的时候通过一个WinFormHost包含一个WinForm控件的形式,以添加两个NumericUpDown为例,我们可以这样写:

<WinFormHost:WindowsFormsHost Canvas.Left="820" Canvas.Top="170" Height="20" Width="101">

        <WinForm:NumericUpDown x:Name="SectionWidth" Maximum="500" Minimum="100" Increment="10" Value="300" ValueChanged="SectionSize_ValueChanged" />

</WinFormHost:WindowsFormsHost>

<WinFormHost:WindowsFormsHost Canvas.Left="820" Canvas.Top="196" Height="20" Width="101">

        <WinForm:NumericUpDown x:Name="SectionHeight" Maximum="500" Minimum="100" Increment="10" Value="300" ValueChanged="SectionSize_ValueChanged" />

</WinFormHost:WindowsFormsHost>

 

posted @ 2012-07-19 19:53  但,我知道  阅读(457)  评论(0编辑  收藏  举报