本文整理汇总了C#中System.Windows.Media.Animation.ColorAnimation类的典型用法代码示例。如果您正苦于以下问题:C# ColorAnimation类的具体用法?C# ColorAnimation怎么用?C# ColorAnimation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ColorAnimation类属于System.Windows.Media.Animation命名空间,在下文中一共展示了ColorAnimation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BtnColorAnimationStart_Click
private void BtnColorAnimationStart_Click(object sender, RoutedEventArgs e)
{
ColorAnimation animation = new ColorAnimation(Colors.Blue, new Duration(TimeSpan.FromSeconds(5)));
animation.AutoReverse = true;
SolidColorBrush brush = (sender as FrameworkElement).FindResource("brush") as SolidColorBrush;
brush.BeginAnimation(SolidColorBrush.ColorProperty, animation);
}
示例2: StoryboardTargetTest
public void StoryboardTargetTest()
{
XamlNamespaces namespaces = new XamlNamespaces("http://schemas.microsoft.com/winfx/2006/xaml/presentation");
ColorAnimation colorAnimation = new ColorAnimation { From = Colors.Green, To = Colors.Blue };
Storyboard.SetTargetProperty(colorAnimation, PropertyPath.Parse("(Control.Background).(SolidColorBrush.Color)", namespaces));
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(colorAnimation);
TestRootClock rootClock = new TestRootClock();
Control control = new Control();
control.SetAnimatableRootClock(new AnimatableRootClock(rootClock, true));
control.Background = new SolidColorBrush(Colors.Red);
storyboard.Begin(control);
rootClock.Tick(TimeSpan.FromSeconds(0));
Assert.AreEqual(Colors.Green, ((SolidColorBrush)control.Background).Color);
rootClock.Tick(TimeSpan.FromSeconds(0.5));
Assert.IsTrue(Color.FromArgb(255, 0, (byte)(Colors.Green.G / 2), (byte)(Colors.Blue.B / 2)).IsClose(((SolidColorBrush)control.Background).Color));
rootClock.Tick(TimeSpan.FromSeconds(1));
Assert.AreEqual(Colors.Blue, ((SolidColorBrush)control.Background).Color);
}
示例3: Paddle
public Paddle()
{
// Sets up the body part's shape.
this.Shape = new Polygon
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
StrokeThickness = 3.0,
Opacity = 1.0,
Fill = Brushes.Orange,
Stroke = Brushes.Black
};
this.state = PaddleState.PreGame;
// Sets up the appear animation.
this.AppearAnimation = new Storyboard();
DoubleAnimation da = new DoubleAnimation(1.0, new Duration(Paddle.AppearAnimationDuration));
Storyboard.SetTarget(da, this.Shape);
Storyboard.SetTargetProperty(da, new PropertyPath(Polygon.OpacityProperty));
this.AppearAnimation.Children.Add(da);
// Sets up the hit animation.
this.FillAnimation = new Storyboard();
ColorAnimation ca = new ColorAnimation(Colors.Red, Colors.Orange, new Duration(Paddle.HitAnimationDuration));
Storyboard.SetTarget(ca, this.Shape);
Storyboard.SetTargetProperty(ca, new PropertyPath("Fill.Color", new object[] { Polygon.FillProperty, SolidColorBrush.ColorProperty }));
this.FillAnimation.Children.Add(ca);
this.State = PaddleState.PreGame;
}
示例4: MatchFinished
public void MatchFinished(bool isAccepted)
{
if (!isAccepted)
{
ColorAnimation opacityOut = new ColorAnimation(Colors.Transparent, new Duration(TimeSpan.FromSeconds(0.5)));
card1.BeginAnimation(Rectangle.FillProperty, opacityOut, HandoffBehavior.SnapshotAndReplace);
card2.BeginAnimation(Rectangle.FillProperty, opacityOut, HandoffBehavior.SnapshotAndReplace);
card3.BeginAnimation(Rectangle.FillProperty, opacityOut, HandoffBehavior.SnapshotAndReplace);
}
else
{
ScaleTransform scale = new ScaleTransform(1.0, 1.0, card1.Width / 2, card1.Height / 2);
DoubleAnimation scaleOutAnim = new DoubleAnimation(1.0, 10.0, new Duration(TimeSpan.FromSeconds(0.5)));
card1.RenderTransform = scale;
card2.RenderTransform = scale;
card3.RenderTransform = scale;
scale.BeginAnimation(ScaleTransform.ScaleXProperty, scaleOutAnim, HandoffBehavior.SnapshotAndReplace);
scale.BeginAnimation(ScaleTransform.ScaleYProperty, scaleOutAnim, HandoffBehavior.SnapshotAndReplace);
scaleOutAnim.Completed += new EventHandler(scaleOutAnim_Completed);
DoubleAnimation opacityOutAnim = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(0.5)));
card1.BeginAnimation(Rectangle.OpacityProperty, opacityOutAnim, HandoffBehavior.SnapshotAndReplace);
card2.BeginAnimation(Rectangle.OpacityProperty, opacityOutAnim, HandoffBehavior.SnapshotAndReplace);
card3.BeginAnimation(Rectangle.OpacityProperty, opacityOutAnim, HandoffBehavior.SnapshotAndReplace);
}
}
示例5: NewHighlighter
/**
* This class is intended to hold templates for any animations that need
* to be created.
* This was first created to allow easy creation of storyboards to be able
* to highlight the board to show the ranks and files of the board seperately.
*/
/// <summary>
/// Highlights a square with a given colour. The square flashes this given colour
/// </summary>
public static Storyboard NewHighlighter(Square s, Brush brush, int delay)
{
int beginFadeIn = 0;
int beginFadeOut = beginFadeIn + 300;
Duration duration = new Duration(TimeSpan.FromMilliseconds(200));
ColorAnimation fadeIn = new ColorAnimation()
{
From = ((SolidColorBrush)(s.rectangle.Fill)).Color,
To = (brush as SolidColorBrush).Color,
Duration = duration,
BeginTime = TimeSpan.FromMilliseconds(beginFadeIn)
};
ColorAnimation fadeOut = new ColorAnimation()
{
From = (brush as SolidColorBrush).Color,
To = (s.rectangle.Fill as SolidColorBrush).Color,
Duration = duration,
BeginTime = TimeSpan.FromMilliseconds(beginFadeOut)
};
Storyboard.SetTarget(fadeIn, s.rectangle);
Storyboard.SetTargetProperty(fadeIn, new PropertyPath("Fill.Color"));
Storyboard.SetTarget(fadeOut, s.rectangle);
Storyboard.SetTargetProperty(fadeOut, new PropertyPath("Fill.Color"));
Storyboard highlight = new Storyboard();
highlight.Children.Add(fadeIn);
highlight.Children.Add(fadeOut);
return highlight;
}
示例6: SetRadius
internal void SetRadius(double radius, string foreTo,
TimeSpan duration)
{
if (radius > 200)
{
radius = 200;
}
Color foreToColor = Colors.Red;
try
{
foreToColor =
(Color)ColorConverter.ConvertFromString(foreTo);
}
catch
{
// Ignore color conversion failure.
}
Duration animationLength = new Duration(duration);
DoubleAnimation radiusAnimation = new DoubleAnimation(
radius * 2, animationLength);
ColorAnimation colorAnimation = new ColorAnimation(
foreToColor, animationLength);
AnimatableEllipse.BeginAnimation(Ellipse.HeightProperty,
radiusAnimation);
AnimatableEllipse.BeginAnimation(Ellipse.WidthProperty,
radiusAnimation);
((RadialGradientBrush)AnimatableEllipse.Fill).GradientStops[1]
.BeginAnimation(GradientStop.ColorProperty, colorAnimation);
}
示例7: OnlineStatusControl
public OnlineStatusControl()
{
InitializeComponent();
story = new Storyboard();
ColorAnimation animation1 = new ColorAnimation();
Storyboard.SetTarget(animation1, ((RadialGradientBrush)this.ellipse.Fill).GradientStops[0]);
Storyboard.SetTargetProperty(
animation1, new PropertyPath(GradientStop.ColorProperty));
animation1.Duration = new Duration(new TimeSpan(0, 0, 1)); ;
animation1.To = Colors.White;
story.Stop();
story.Children.Add(animation1);
ColorAnimation animation2 = new ColorAnimation();
Storyboard.SetTarget(animation2, ((RadialGradientBrush)this.ellipse.Fill).GradientStops[1]);
Storyboard.SetTargetProperty(
animation2, new PropertyPath(GradientStop.ColorProperty));
animation2.Duration = new Duration(new TimeSpan(0, 0, 1)); ;
animation2.To = Common.MyColor.ConvertColor("#ff2ADC16");
story.Stop();
story.Children.Add(animation2);
story.AutoReverse = true;
story.RepeatBehavior = RepeatBehavior.Forever;
this.LayoutRoot.Resources.Add("sotry_", story);
OnlineStatus = 1;
}
示例8: AddClicked
private void AddClicked(object sender, RoutedEventArgs e)
{
e.Handled = true;
// A double-click can only select a marker in its own list
// (Little bug here: double-clicking in the empty zone of a list with a selected marker adds it)
if (sender is ListBox && ((ListBox) sender).SelectedIndex == -1) return;
if (recentList.SelectedIndex != -1) MarkerModel = (DataNew.Entities.Marker)recentList.SelectedItem;
if (allList.SelectedIndex != -1) MarkerModel = (DataNew.Entities.Marker)allList.SelectedItem;
if (defaultList.SelectedIndex != -1)
{
var m = ((DefaultMarkerModel) defaultList.SelectedItem);
m.Name = nameBox.Text;
MarkerModel = m.Clone();
}
if (MarkerModel == null) return;
int qty;
if (!int.TryParse(quantityBox.Text, out qty) || qty < 0)
{
var anim = new ColorAnimation(Colors.Red, new Duration(TimeSpan.FromMilliseconds(800)))
{AutoReverse = true};
validationBrush.BeginAnimation(SolidColorBrush.ColorProperty, anim, HandoffBehavior.Compose);
return;
}
Program.GameEngine.AddRecentMarker(MarkerModel);
DialogResult = true;
}
示例9: MyVectorCanvas
/// <summary> </summary>
/// <param name="mapControl"></param>
public MyVectorCanvas(MapView mapView)
: base(mapView)
{
var myPolygon = new MapPolygon()
{
Points = new PointCollection{ new Point(20,40), new Point(20, 50), new Point(30,50), new Point(30,40) }
};
myPolygon.Fill = new SolidColorBrush(Colors.Blue);
myPolygon.Stroke = new SolidColorBrush(Colors.Black);
myPolygon.InvariantStrokeThickness = 3;
Children.Add(myPolygon);
//// http://msdn.microsoft.com/en-us/library/system.windows.media.animation.coloranimation.aspx
SolidColorBrush myAnimatedBrush = new SolidColorBrush();
myAnimatedBrush.Color = Colors.Blue;
myPolygon.Fill = myAnimatedBrush;
MapView.RegisterName("MyAnimatedBrush", myAnimatedBrush);
ColorAnimation mouseEnterColorAnimation = new ColorAnimation();
mouseEnterColorAnimation.From = Colors.Blue;
mouseEnterColorAnimation.To = Colors.Red;
mouseEnterColorAnimation.Duration = TimeSpan.FromMilliseconds(250);
mouseEnterColorAnimation.AutoReverse = true;
Storyboard.SetTargetName(mouseEnterColorAnimation, "MyAnimatedBrush");
Storyboard.SetTargetProperty(mouseEnterColorAnimation, new PropertyPath(SolidColorBrush.ColorProperty));
Storyboard mouseEnterStoryboard = new Storyboard();
mouseEnterStoryboard.Children.Add(mouseEnterColorAnimation);
myPolygon.MouseEnter += delegate(object msender, MouseEventArgs args)
{
mouseEnterStoryboard.Begin(MapView);
};
}
示例10: FeedWin
/// <summary>
/// Constructor! Hurrah!
/// </summary>
/// <param name="feeditem"></param>
public FeedWin(FeedConfigItem feeditem)
{
Log.Debug("Constructing feedwin. GUID:{0} URL: {1}", feeditem.Guid, feeditem.Url);
InitializeComponent();
fci = feeditem;
Width = fci.Width;
Left = fci.Position.X;
Top = fci.Position.Y;
//Kick of thread to figure out what sort of plugin to load for this sort of feed.
ThreadPool.QueueUserWorkItem(state => GetFeedType(fci));
//Set up the animations for the mouseovers
fadein = new ColorAnimation { AutoReverse = false, From = fci.DefaultColor, To = fci.HoverColor, Duration = new Duration(TimeSpan.FromMilliseconds(200)), RepeatBehavior = new RepeatBehavior(1) };
fadeout = new ColorAnimation { AutoReverse = false, To = fci.DefaultColor, From = fci.HoverColor, Duration = new Duration(TimeSpan.FromMilliseconds(200)), RepeatBehavior = new RepeatBehavior(1) };
textbrush = new SolidColorBrush(feeditem.DefaultColor);
//Add the right number of textblocks to the form, depending on what the user asked for.
for (var ii = 0; ii < fci.DisplayedItems; ii++)
{
maingrid.RowDefinitions.Add(new RowDefinition());
var textblock = new TextBlock
{
Style = (Style)FindResource("linkTextStyle"),
Name = string.Format("TextBlock{0}", ii + 1),
TextTrimming = TextTrimming.CharacterEllipsis,
Foreground = textbrush.Clone(),
Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)),
FontFamily = fci.FontFamily,
FontSize = fci.FontSize,
FontStyle = fci.FontStyle,
FontWeight = fci.FontWeight,
Visibility = Visibility.Collapsed
};
textblock.SetValue(Grid.ColumnSpanProperty, 2);
RegisterName(textblock.Name, textblock);
maingrid.Children.Add(textblock);
Grid.SetRow(textblock, ii + 1);
}
maingrid.RowDefinitions.Add(new RowDefinition());
movehandle = new Image();
movehandle.Width = movehandle.Height = 16;
movehandle.Name = "movehandle";
movehandle.HorizontalAlignment = HorizontalAlignment.Left;
movehandle.Cursor = Cursors.SizeAll;
movehandle.Source = new BitmapImage(new Uri("/Feedling;component/Resources/move-icon.png", UriKind.Relative));
movehandle.SetValue(Grid.ColumnSpanProperty, 2);
RegisterName(movehandle.Name, movehandle);
maingrid.Children.Add(movehandle);
movehandle.MouseDown += movehandle_MouseDown;
movehandle.Visibility = Visibility.Collapsed;
Grid.SetRow(movehandle, maingrid.RowDefinitions.Count);
}
示例11: mouseDown
public void mouseDown(object sender, MouseButtonEventArgs e)
{
Cell c = sender as Cell;
Color color = c.color;
if (color == Colors.White)
{
ColorAnimation a = new ColorAnimation();
a.From = Colors.White;
a.To = Colors.Red;
a.Duration = TimeSpan.FromSeconds(0.2);
a.RepeatBehavior = new RepeatBehavior(3);
a.Completed += (s, ev) => {
End.Visibility = System.Windows.Visibility.Visible;
EndScore.Content = score;
};
c.Background.BeginAnimation(SolidColorBrush.ColorProperty, a);
Playground.IsEnabled = false;
return;
}
else if (color == Colors.Black)
{
if (!lines[3].Contains(c))
{
return;
}
ColorAnimation a = new ColorAnimation();
a.From = color;
a.To = c.color = Colors.Gray;
a.Duration = TimeSpan.FromSeconds(0.2);
c.Background.BeginAnimation(SolidColorBrush.ColorProperty, a);
score++;
Score.Content = score;
}
Cell[] line4 = lines[3];
ThicknessAnimation animation = new ThicknessAnimation();
for (int i = 4; i >= 0; i--)
{
Cell[] line;
if (i >= 4) line = line4;
else if (i > 0) line = lines[i] = lines[i - 1];
else line = lines[0] = newLine(0);
for (int j = 0; j < 4; j++)
{
Cell cell = line[j];
animation.From = new Thickness(j * cellWidth, (i - 1) * cellHeight, 0, 0);
animation.To = new Thickness(j * cellWidth, i * cellHeight, 0, 0);
animation.Duration = TimeSpan.FromSeconds(0.2);
animation.Completed += (s, ev) => cell.Margin = new Thickness(j * cellWidth, (i + 1) * cellHeight, 0, 0);
if (i == 4)
{
animation.Completed += (s, ev) => Playground.Children.Remove(cell);
}
cell.BeginAnimation(Grid.MarginProperty, animation);
}
}
}
示例12: Verify
public void Verify(DPFP.Sample Sample)
{
DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);
// Check quality of the sample and start verification if it's good
// TODO: move to a separate task
if (features != null)
{
// Compare the feature set with our template
DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
Verificator.Verify(features, Template, ref result);
if (result.Verified)
{
this.Dispatcher.Invoke(() =>
{
if (this.ClockShow != null)
this.ClockShow.Controller.Pause();
ColorAnimation animation = new ColorAnimation();
animation.From = (this.UIFinger_Printer.Foreground as SolidColorBrush).Color;
animation.To = Colors.Green;
animation.Duration = new Duration(TimeSpan.FromMilliseconds(450));
animation.EasingFunction = new PowerEase() { Power = 5, EasingMode = EasingMode.EaseInOut };
animation.Completed += (s,e) =>
{
App.curUser = UserData.Info(this.cacheName);
App.curUserID = App.curUser.ID;
if (this.UIAutoLogin.IsChecked.Value)
{
App.cache.hashUserName = App.getHash(App.curUserID);
App.cache.userName = Encrypt.EncryptString(this.UITxtName.Text.Trim(), FunctionStatics.getCPUID());
AltaCache.Write(App.CacheName, App.cache);
}
else
{
App.cache.userName = string.Empty;
App.cache.hashUserName = string.Empty;
}
this.UIFullName.Text = App.curUser.Full_Name;
this.UILoginFinger.Animation_Translate_Frame(double.NaN, double.NaN, 400, double.NaN, 500);
this.UILoginSusscess.Animation_Translate_Frame(-400, double.NaN, 0, double.NaN, 500, () => { LoadData(); });
};
this.ClockHide = animation.CreateClock();
this.UIFinger_Printer.Foreground.ApplyAnimationClock(SolidColorBrush.ColorProperty, ClockHide);
this.UIFinger_Status.Text = string.Empty;
});
this.Stop();
}
else
{
this.Dispatcher.Invoke(() =>
{
this.UIFinger_Status.Text = "Try again ...";
});
}
}
}
示例13: WrittenCheckControl
public WrittenCheckControl()
{
InitializeComponent();
m_textBoxAnswerAnimation = new ColorAnimation();
m_textBoxAnswerAnimation.Duration = new TimeSpan(0, 0, 0, 0, 300);
m_textBoxAnswerAnimation.To = Colors.White;
textBoxAnswer.Background = new SolidColorBrush(Colors.White);
}
示例14: AnimateColor
public static void AnimateColor(SolidColorBrush from, SolidColorBrush to, UIElement control, double duration)
{
SolidColorBrush myBrush = new SolidColorBrush();
myBrush = from;
ColorAnimation myColorAnimation = new ColorAnimation();
myColorAnimation.From = from.Color;
myColorAnimation.To = to.Color;
myColorAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration));
myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);
control.GetType().GetProperty("Background").SetValue(control, myBrush);
}
示例15: FadeOut
public void FadeOut()
{
FadeLabel FadeLabel = this;
var changeColorAnimation = new ColorAnimation(Color.FromRgb(NoHoverColor, NoHoverColor, NoHoverColor), TimeSpan.FromSeconds(0.5));
Storyboard s = new Storyboard();
s.Duration = new Duration(new TimeSpan(0, 0, 1));
s.Children.Add(changeColorAnimation);
Storyboard.SetTarget(changeColorAnimation, FadeLabel);
Storyboard.SetTargetProperty(changeColorAnimation, new PropertyPath("Foreground.Color"));
s.Begin();
}