当前位置: 首页>>代码示例>>C#>>正文


C# AnimationClock.Animate方法代码示例

本文整理汇总了C#中System.Windows.Media.Animation.AnimationClock.Animate方法的典型用法代码示例。如果您正苦于以下问题:C# AnimationClock.Animate方法的具体用法?C# AnimationClock.Animate怎么用?C# AnimationClock.Animate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Animation.AnimationClock的用法示例。


在下文中一共展示了AnimationClock.Animate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: XamlWindow

        public XamlWindow()
        {
            Dispatcher d1 = Dispatcher.CurrentDispatcher;
            Dispatcher d2 = Dispatcher.CurrentDispatcher;

            SolidColorBrush solidBrush = new SolidColorBrush();

            StackPanel stack = new StackPanel();
            Label label = new Label();
            label.Content = "Hello world";
            label.Margin = new Thickness(20, 0, 0, 0);
            stack.Children.Add(label);
            label.ForeBrush = solidBrush;

            label = new Label();
            label.Content = "Hello world";
            label.HorizontalAlignment = HorizontalAlignment.Right;
            label.Margin = new Thickness(0, 0, 20, 0);
            stack.Children.Add(label);

            label = new Label();
            label.Content = "Hello world";
            label.HorizontalAlignment = HorizontalAlignment.Center;
            label.Margin = new Thickness(60, 0, 0, 0);
            Font font = new Font(FontFamily.GenericSerif, 24, FontStyle.Regular);
            label.Font = font;
            stack.Children.Add(label);

            Rectangle rect = new Rectangle();
            rect.Width = 100;
            rect.Height = 100;
            rect.HorizontalAlignment = HorizontalAlignment.Right;
            GradientBrush gradient = new GradientBrush();
            gradient.StartPoint = new Point(0, .5f);
            gradient.EndPoint = new Point(1, .5f);
            gradient.GradientStops.Add(new GradientStop(new Color(1f, 1f, 0f, 1f), 0));
            gradient.GradientStops.Add(new GradientStop(new Color(0, 0, 1f, 1f), 1));
            rect.Fill = gradient;
            stack.Children.Add(rect);

            BitmapSource bitmap;
            using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("XamlTest.Flames.bmp"))
            {
                bitmap = BitmapSource.Create(stream);
            }
            Image image = new Image();
            image.Stretch = Stretch.None;
            image.ImageSource = bitmap;
            stack.Children.Add(image);

            ImageBrush brush = new ImageBrush();
            brush.ImageSource = bitmap;
            brush.Stretch = Stretch.None;
            label.ForeBrush = brush;

            Content = stack;

            FloatAnimation anim = new FloatAnimation();
            anim.From = 50;
            anim.To = 300;
            anim.Duration = new Duration(TimeSpan.FromMilliseconds(10000));
            anim.RepeatBehavior = RepeatBehavior.Forever;
            anim.AutoReverse = true;
            myClock = anim.CreateClock();
            myClock.Animate(rect, Rectangle.WidthProperty);

            //new Thread(() =>
            //    {
            //        //Thread.Sleep(2000);
            //        Random rand = new Random();
            //        while (true)
            //        {
            //            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new EmptyDelegate(() =>
            //                {
            //                    Color newColor = new Color((byte)(rand.Next() % 256), (byte)(rand.Next() % 256), (byte)(rand.Next() % 256), (byte)(rand.Next() % 256));
            //                    solidBrush.Color = newColor;
            //                    rect.Width += 5;
            //                    if (rect.Width > 300)
            //                        rect.Width = 200;
            //                }));
            //        }
            //    }
            //).Start();
        }
开发者ID:koush,项目名称:Xaml,代码行数:84,代码来源:XamlWindow.cs

示例2: MainWindow

        public MainWindow(WindowActivity activity)
            : base(activity)
        {
            SolidColorBrush solidBrush = new SolidColorBrush();

            StackPanel stack = new StackPanel();

            Rectangle rect = new Rectangle();
            rect.Width = 100;
            rect.Height = 100;
            rect.HorizontalAlignment = HorizontalAlignment.Right;
            GradientBrush gradient = new GradientBrush();
            gradient.StartPoint = new Point(0, .5f);
            gradient.EndPoint = new Point(1, .5f);
            gradient.GradientStops.Add(new GradientStop(new Color(1f, 1f, 0f, 1f), 0));
            gradient.GradientStops.Add(new GradientStop(new Color(0, 0, 1f, 1f), 1));
            rect.Fill = gradient;
            stack.Children.Add(rect);

            BitmapSource src = BitmapSource.Create(WindowActivity, R.drawable.funny);

            WrapPanel wrap = new WrapPanel();
            //wrap.HorizontalAlignment = HorizontalAlignment.Center;
            wrap.Orientation = Orientation.Horizontal;

            for (int i = 0; i < 8; i++)
            {
                Image img = new Image();
                img.Margin = new Thickness(5,5,5,5);
                img.ImageSource = src;
                img.HorizontalAlignment = HorizontalAlignment.Center;
                wrap.Children.Add(img);
            }

            stack.HorizontalAlignment = HorizontalAlignment.Stretch;
            stack.Children.Add(wrap);

            Content = stack;

            FloatAnimation anim = new FloatAnimation();
            anim.From = 50;
            anim.To = 300;
            anim.Duration = new Duration(TimeSpan.FromMilliseconds(10000));
            anim.RepeatBehavior = RepeatBehavior.Forever;
            anim.AutoReverse = true;
            myClock = anim.CreateClock();
            myClock.Animate(rect, Rectangle.WidthProperty);

            //myTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(1000), (e, o) => Console.WriteLine("Foo"), Dispatcher.CurrentDispatcher);
            //myTimer.Start();

            //Content = img;
        }
开发者ID:koush,项目名称:Firefly,代码行数:53,代码来源:MainActivity.cs


注:本文中的System.Windows.Media.Animation.AnimationClock.Animate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。