zoukankan      html  css  js  c++  java
  • WPF 轨迹动画

    1.后台

      public MainWindow()
            {
                InitializeComponent();
                /// <summary>
                /// Window2.xaml 的交互逻辑
                /// </summary>
                //var canvas = new Canvas();
    
                //Content = canvas; 
                var points =
                    new List<Point>()
                    {
                        new Point(10, 10),
                        new Point(10, 90),
                        new Point(70, 90)
                    };
                var sb = new Storyboard();
                sb.Completed += Sb_Completed;
                for (int i = 0; i < points.Count - 1; i++)
                {
                    var lineGeometry = new LineGeometry(points[i], points[i]);
                    var path =
                        new Path()
                        {
                            Stroke = Brushes.Red,
                            StrokeThickness = 2,
                            Data = lineGeometry
                        };
                    canvas.Children.Add(path);
                    var animation =
                        new PointAnimation(points[i], points[i + 1], new Duration(TimeSpan.FromMilliseconds(1000)))
                        {
                            BeginTime = TimeSpan.FromMilliseconds(i * 1010)
                        };
                    sb.Children.Add(animation);
                    RegisterName("geometry" + i, lineGeometry);
                    Storyboard.SetTargetName(animation, "geometry" + i);
                    Storyboard.SetTargetProperty(animation, new PropertyPath(LineGeometry.EndPointProperty));
                }
                MouseDown += (s, e) => sb.Begin(this);
            }
    
            private void Sb_Completed(object sender, EventArgs e)
            {
                this.Dispatcher.BeginInvoke(new Action(delegate { lblTest.Content = "测试哦"; }));
            }

    2.xaml

       <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="160px">
                </RowDefinition>
                <RowDefinition Height="*" x:Name="row1">
                </RowDefinition>
                <RowDefinition Height="120">
                </RowDefinition>
            </Grid.RowDefinitions>
            <Canvas Grid.Row="1" x:Name="canvas"></Canvas>
            <Label Grid.Row="2" Name="lblTest"></Label>
        </Grid>
  • 相关阅读:
    HTML表格的简单使用1
    守卫路由使用
    CSS高度塌陷问题解决方案
    CSS导航条nav简单样式
    Linux学习
    TYpeScript接口的使用
    javaScript中自定义sort中的比较函数,用于比较字符串长度,数值大小
    給eclipse添加字体,设置字体
    tomcat自动URLDecode解码问题(+号变空格)
    时间管理
  • 原文地址:https://www.cnblogs.com/guosier/p/14830190.html
Copyright © 2011-2022 走看看