博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
与众不同 windows phone (17) - Graphic and Animation(画图和动画)
阅读量:6651 次
发布时间:2019-06-25

本文共 8595 字,大约阅读时间需要 28 分钟。

原文:

与众不同 windows phone (17) - Graphic and Animation(画图和动画)

作者:
介绍
与众不同 windows phone 7.5 (sdk 7.1) 之画图和动画

  • 图形
  • 画笔
  • 转换
  • 动画
  • 缓动

示例
1、图形(Shape)
ShapeDemo.xaml

ShapeDemo.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;using Microsoft.Phone.Controls;namespace Demo.GraphicAndAnimation{    public partial class ShapeDemo : PhoneApplicationPage    {        public ShapeDemo()        {            InitializeComponent();            this.Loaded += new RoutedEventHandler(ShapeDemo_Loaded);        }        void ShapeDemo_Loaded(object sender, RoutedEventArgs e)        {            // 以 代码 的方式绘制图形            // 画多边形            Polygon polygon = new Polygon();            polygon.Stroke = new SolidColorBrush(Colors.Purple);            polygon.StrokeThickness = 3d;            polygon.Points.Add(new Point(0, 0));            polygon.Points.Add(new Point(100, 0));            polygon.Points.Add(new Point(0, 100));            polygon.Points.Add(new Point(100, 100));            root.Children.Add(polygon);        }    }}

2、画笔(Brush)
BrushDemo.xaml

BrushDemo.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;using Microsoft.Phone.Controls;namespace Demo.GraphicAndAnimation{    public partial class BrushDemo : PhoneApplicationPage    {        public BrushDemo()        {            InitializeComponent();            this.Loaded += new RoutedEventHandler(BrushDemo_Loaded);        }        void BrushDemo_Loaded(object sender, RoutedEventArgs e)        {            // 以 代码 的方式应用画笔            // 使用放射性渐变画笔            GradientStop gs1 = new GradientStop();            gs1.Color = Colors.Red;            gs1.Offset = 0d;            GradientStop gs2 = new GradientStop();            gs2.Color = Colors.Green;            gs2.Offset = 0.3d;            GradientStop gs3 = new GradientStop();            gs3.Color = Colors.Blue;            gs3.Offset = 1d;            LinearGradientBrush brush = new LinearGradientBrush();            brush.StartPoint = new Point(0, 0);            brush.EndPoint = new Point(1, 1);            brush.GradientStops.Add(gs1);            brush.GradientStops.Add(gs2);            brush.GradientStops.Add(gs3);            Rectangle rect = new Rectangle();            rect.Width = 200d;            rect.Height = 200d;            rect.Fill = brush;            root.Children.Add(rect);        }    }}

3、转换(Transform)
TransformDemo.xaml

TransformDemo.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;using Microsoft.Phone.Controls;namespace Demo.GraphicAndAnimation{    public partial class TransformDemo : PhoneApplicationPage    {        public TransformDemo()        {            InitializeComponent();            this.Loaded += new RoutedEventHandler(TransformDemo_Loaded);        }        void TransformDemo_Loaded(object sender, RoutedEventArgs e)        {            // 以 代码 的方式应用转换            // 使用旋转转换            RotateTransform rt = new RotateTransform();            rt.Angle = 30;            Rectangle rect = new Rectangle();            rect.Width = 200d;            rect.Height = 200d;            rect.Fill = new SolidColorBrush(Colors.Green);            rect.RenderTransform = rt;            root.Children.Add(rect);        }    }}

4、动画(Animation)
AnimationDemo.xaml

AnimationDemo.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;using Microsoft.Phone.Controls;namespace Demo.GraphicAndAnimation{    public partial class AnimationDemo : PhoneApplicationPage    {        public AnimationDemo()        {            InitializeComponent();            this.Loaded += new RoutedEventHandler(AnimationDemo_Loaded);        }        void AnimationDemo_Loaded(object sender, RoutedEventArgs e)        {            // 以 代码 的方式增加动画效果            // 画个圆            Ellipse ellipse = new Ellipse();            ellipse.Width = 100d;            ellipse.Height = 100d;            ellipse.Fill = new SolidColorBrush(Colors.Green);            root.Children.Add(ellipse);            // 为上面画的圆增加颜色动画效果            ColorAnimation ca = new ColorAnimation();            ca.Duration = TimeSpan.FromSeconds(2);            ca.From = Colors.Green;            ca.To = Colors.Blue;            ca.AutoReverse = true;            ca.RepeatBehavior = RepeatBehavior.Forever;            Storyboard.SetTarget(ca, ellipse);            Storyboard.SetTargetProperty(ca, new PropertyPath("(Ellipse.Fill).(SolidColorBrush.Color)"));            Storyboard s = new Storyboard();            s.Children.Add(ca);            s.Begin();        }    }}

5、缓动(Easing)
EasingDemo.xaml

EasingDemo.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;using Microsoft.Phone.Controls;namespace Demo.GraphicAndAnimation{    public partial class EasingDemo : PhoneApplicationPage    {        public EasingDemo()        {            InitializeComponent();                         this.Loaded += new RoutedEventHandler(AnimationDemo_Loaded);        }        void AnimationDemo_Loaded(object sender, RoutedEventArgs e)        {            // 以 代码 的方式增加动画效果            // 画个圆            Ellipse ellipse = new Ellipse();            ellipse.Width = 100d;            ellipse.Height = 100d;            ellipse.Fill = new SolidColorBrush(Colors.Green);            root.Children.Add(ellipse);            // 为上面画的圆增加颜色动画效果            ColorAnimation ca = new ColorAnimation();            ca.Duration = TimeSpan.FromSeconds(5);            ca.From = Colors.Green;            ca.To = Colors.Blue;            ca.AutoReverse = true;            ca.RepeatBehavior = RepeatBehavior.Forever;            // 为颜色动画增加缓动效果            EasingFunctionBase easing = new BounceEase();            easing.EasingMode = EasingMode.EaseInOut;            ca.EasingFunction = easing;            Storyboard.SetTarget(ca, ellipse);            Storyboard.SetTargetProperty(ca, new PropertyPath("(Ellipse.Fill).(SolidColorBrush.Color)"));            Storyboard s = new Storyboard();            s.Children.Add(ca);            s.Begin();        }    }}

OK

你可能感兴趣的文章
在IIS8添加WCF服务支持
查看>>
对话微信头条产品总监:优质原创内容的个性化推送是如何实现的
查看>>
烂泥:Windows Server 2008如何修改用户的密码
查看>>
自媒体掘金时代已来临,你准备好了吗?
查看>>
外部排序(java实现)
查看>>
Android之系统自带的文字外观设置及实际显示效果图
查看>>
Windows_Programing_English_To_Chinese_1_MSVC_C运行库
查看>>
input默认值设置
查看>>
谷歌语言标准中,C++成绝对的佼佼者
查看>>
wcf系列学习5天速成——第三天 事务的使用
查看>>
编程基础-字符篇-(1)
查看>>
深入 Python :Dive Into Python 中文版 重定向
查看>>
Apache+Django性能优化之mod_wsgi篇
查看>>
cocos2d/box2d技术问题汇总
查看>>
mysqldump 常用备份选项,只备份数据或结构的方法
查看>>
一个用户登录权限的基本例子
查看>>
Python标准库——走马观花
查看>>
Decode Ways
查看>>
关于字符串指针不可修改的问题
查看>>
DEFT Linux 7.2,数字取证工具箱
查看>>