本文整理汇总了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();
}
示例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;
}