WPF之感触
2014-03-13 18:01 lee.hunter 阅读(250) 评论(0) 编辑 收藏 举报今年2月份提出了离职,趁着离职之际,学习了WPF,给我的感觉就是使用WPF做一些界面元素要求比较高的功能是一个很不错的选择,尤其是机械工业的软件,比如机组的匹配,设计人员需要直观的看到。
以下是一个WPF的小例子:
实现代码:
<Window x:Class="WPF.Drawing" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Drawing" Height="500" Width="600"> <Grid VerticalAlignment="Center" HorizontalAlignment="Center"> <Line X1="10" Y1="20" X2="260" Y2="20" Stroke="Red" StrokeThickness="10"></Line> <Line X1="10" Y1="40" X2="260" Y2="40" Stroke="Orange" StrokeThickness="6"></Line> <Line X1="10" Y1="200" X2="260" Y2="200" StrokeEndLineCap="Triangle"> <Line.Stroke> <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,0.5"> <GradientStop Color="Blue"></GradientStop> <GradientStop Offset="1"></GradientStop> </LinearGradientBrush> </Line.Stroke> </Line> <Path Stroke="Green" Fill="LawnGreen" StrokeThickness="2"> <Path.Data> <PathGeometry> <PathFigure IsClosed="True" StartPoint="0,0"> <LineSegment Point="150,0"></LineSegment> <LineSegment Point="150,30"></LineSegment> <LineSegment Point="90,30"></LineSegment> <LineSegment Point="90,150"></LineSegment> <LineSegment Point="60,150"></LineSegment> <LineSegment Point="60,30"></LineSegment> <LineSegment Point="0,30"></LineSegment> </PathFigure> </PathGeometry> </Path.Data> </Path> <Path Stroke="Black" StrokeThickness="2"> <Path.Data> <PathGeometry> <PathFigure StartPoint="0,0"> <BezierSegment Point1="250,0" Point2="50,200" Point3="300,200"></BezierSegment> </PathFigure> </PathGeometry> </Path.Data> </Path> <Path Stroke="Black" StrokeThickness="2"> <Path.Data> <PathGeometry> <PathFigure StartPoint="0,200"> <QuadraticBezierSegment Point1="150,-100" Point2="300,200"></QuadraticBezierSegment> </PathFigure> </PathGeometry> </Path.Data> </Path> <Button Height="30" Width="60" HorizontalAlignment="Right" VerticalAlignment="Top" Click="Button_Click" >Moveing</Button> <Button Height="30" Width="60" VerticalAlignment="Top" Margin="169,0,72,0" Click="Button_Click_1">Frame</Button> </Grid> </Window>
帧,实现代码:
<Window x:Class="WPF.DrawFrame" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="DrawFrame" Height="300" Width="600"> <Grid> <Button Content="Move" VerticalAlignment="Top" HorizontalAlignment="Left" Width="80" Height="80" Click="Button_Click"> <Button.RenderTransform> <TranslateTransform x:Name="tt" X="0" Y="0"></TranslateTransform> </Button.RenderTransform> </Button> </Grid> </Window> 后台代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Media.Animation; namespace WPF { /// <summary> /// DrawFrame.xaml 的交互逻辑 /// </summary> public partial class DrawFrame : Window { public DrawFrame() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { //创建动画 DoubleAnimationUsingKeyFrames dakX = new DoubleAnimationUsingKeyFrames(); dakX.Duration = new Duration(TimeSpan.FromMilliseconds(1000)); //创建,添加关键帧 SplineDoubleKeyFrame df = new SplineDoubleKeyFrame(); df.KeyTime = KeyTime.FromPercent(1); df.Value = 400; KeySpline ks = new KeySpline(); ks.ControlPoint1 = new Point(0, 1); ks.ControlPoint2 = new Point(1, 0); df.KeySpline = ks; dakX.KeyFrames.Add(df); //执行动画 this.tt.BeginAnimation(TranslateTransform.XProperty, dakX); } } }