WEB开发网
开发学院图形图像Flash Silverlight(11) - 2.0动画之ColorAnimation, Dou... 阅读

Silverlight(11) - 2.0动画之ColorAnimation, DoubleAnimation, PointAnimation, 内插关键帧动画

 2008-11-14 11:50:32 来源:WEB开发网   
核心提示: KeyFrame.xaml.csusing System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Contro

KeyFrame.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
  
namespace Silverlight20.Animation
{
  public partial class KeyFrame : UserControl
  {
    public KeyFrame()
    {
      InitializeComponent();
    }
  
    private void caRectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      caStoryboard.Begin();
    }
  
    private void daRectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      daStoryboard.Begin();
    }
  
    private void paPath_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      paStoryboard.Begin();
    }
  }
}

5、Programmatically.xaml

<UserControl x:Class="Silverlight20.Animation.Programmatically"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel HorizontalAlignment="Left">
  
    <!--
    MouseLeftButtonDown - 在该Canvas上单击鼠标后所执行的事件
    -->
    <Canvas x:Name="canvas" Background="Yellow" Width="640" Height="480" MouseLeftButtonDown="Canvas_MouseLeftButtonDown">
      <Path Fill="Red">
        <Path.Data>
          <EllipseGeometry x:Name="ellipseGeometry" Center="200,100" RadiusX="15" RadiusY="15" />
        </Path.Data>
      </Path>
    </Canvas>
  
    <StackPanel.Resources>
      <Storyboard x:Name="storyboard">
        <PointAnimation
          x:Name="pointAnimation"
          Storyboard.TargetProperty="Center"
          Storyboard.TargetName="ellipseGeometry"
          Duration="0:0:2"/>
      </Storyboard>
    </StackPanel.Resources>
  </StackPanel>
  
</UserControl>

Programmatically.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
  
namespace Silverlight20.Animation
{
  public partial class Programmatically : UserControl
  {
    public Programmatically()
    {
      InitializeComponent();
    }
  
    private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
      // 鼠标相对与canvas的坐标
      double newX = e.GetPosition(canvas).X;
      double newY = e.GetPosition(canvas).Y;
      Point myPoint = new Point(newX, newY);
  
      // 将动画的结束值设置为鼠标的当前坐标
      pointAnimation.To = myPoint;
  
      // 播放动画
      storyboard.Begin();
    }
  }
}

OK

上一页  1 2 3 4 5 

Tags:Silverlight 动画 ColorAnimation

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接