public static ColorAnimation CreateColor(Color to, Duration duration, string targetProperty) { var animation = new ColorAnimation { To = to, Duration = duration, EnableDependentAnimation = true }; Storyboard.SetTargetProperty(animation, targetProperty); return animation; }
public void Animate2Color(Color c) { Storyboard story = new Storyboard(); ColorAnimation animation = new ColorAnimation(); animation.Duration = TimeSpan.FromMilliseconds(600); story.Children.Add(animation); animation.EnableDependentAnimation = true; Storyboard.SetTarget(animation, _border); Storyboard.SetTargetProperty(animation, "(Border.Background).(SolidColorBrush.Color)"); animation.To = c; story.Begin(); }
private static void _bar_Closing(object sender, object e) { var bar = sender as CommandBar; var brush = bar?.Background as SolidColorBrush; if (brush == null) return; var color = GetClosedBackgroundColor(bar); if (color == null) return; ColorAnimation ca = new ColorAnimation() { To = color, Duration = TimeSpan.FromMilliseconds(200) }; Storyboard.SetTarget(ca, brush); Storyboard.SetTargetProperty(ca, "Color"); Storyboard sb = new Storyboard(); sb.Children.Add(ca); sb.Begin(); }
public static Storyboard CreateColorSB(DependencyObject dpnObj, string property, double secondTime, Color to, EasingMode em) { ColorAnimation ca = new ColorAnimation(); ca.Duration = TimeSpan.FromSeconds(secondTime); ca.To = to; CircleEase ce = new CircleEase(); ce.EasingMode = em; ca.EasingFunction = ce; Storyboard.SetTarget(ca, dpnObj); Storyboard.SetTargetProperty(ca, property); Storyboard sb = new Storyboard(); sb.Children.Add(ca); return sb; }
public void Begin() { var colorAnimation = new ColorAnimation { From = this.colorRange.From, To = this.colorRange.To, Duration = new Duration(TimeSpan.FromSeconds(1)), AutoReverse = true, RepeatBehavior = new RepeatBehavior(2) }; var storyboard = new Storyboard(); storyboard.Children.Add(colorAnimation); Storyboard.SetTargetProperty(colorAnimation, "(Control.Background).(SolidColorBrush.Color)"); Storyboard.SetTarget(storyboard, button); storyboard.Begin(); }
public void InitializeFoodsAndFacilitiesLayout() { if (Children == null) return; if (Children.Count < 2) return; try { _mainFragment = Children.OfType<Grid>().FirstOrDefault(); _listFragment = Children.OfType<Grid>().ElementAt(1); } catch { return; } if (_mainFragment == null || _listFragment == null) return; _mainFragment.Name = "_mainFragment"; _listFragment.Name = "_listFragment"; // _mainFragment _mainFragment.HorizontalAlignment = HorizontalAlignment.Stretch; _mainFragment.VerticalAlignment = VerticalAlignment.Stretch; if (_mainFragment.Background == null) _mainFragment.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); // Render transform _listFragment _listFragment.HorizontalAlignment = HorizontalAlignment.Left; _listFragment.VerticalAlignment = VerticalAlignment.Stretch; _listFragment.Width = (Window.Current.Bounds.Width/3)*2; if (_listFragment.Background == null) _listFragment.Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); var animatedTranslateTransform = new TranslateTransform {X = -_listFragment.Width, Y = 0}; _listFragment.RenderTransform = animatedTranslateTransform; _listFragment.RenderTransformOrigin = new Point(0.5, 0.5); _listFragment.UpdateLayout(); // Create a shadow element _shadowFragment = new Grid { Name = "_shadowFragment", Background = new SolidColorBrush(Color.FromArgb(0, 255, 255, 255)), HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch, Visibility = Visibility.Collapsed }; _shadowFragment.Tapped += shadowFragment_Tapped; _shadowFragment.IsHitTestVisible = false; // Set ZIndexes Canvas.SetZIndex(_shadowFragment, 50); Canvas.SetZIndex(_listFragment, 51); Children.Add(_shadowFragment); // Create a new fadeIn animation storyboard _fadeInStoryboard = new Storyboard(); // New double animation var doubleAnimation1 = new DoubleAnimation {Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = 0}; Storyboard.SetTarget(doubleAnimation1, _listFragment); Storyboard.SetTargetProperty(doubleAnimation1, TranslatePath.Path); _fadeInStoryboard.Children.Add(doubleAnimation1); // New color animation for _shadowFragment var colorAnimation1 = new ColorAnimation { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = Color.FromArgb(190, 0, 0, 0) }; Storyboard.SetTarget(colorAnimation1, _shadowFragment); Storyboard.SetTargetProperty(colorAnimation1,ColorPath.Path); _fadeInStoryboard.Children.Add(colorAnimation1); // Create a new fadeOut animation storyboard _fadeOutStoryboard = new Storyboard(); // New double animation var doubleAnimation2 = new DoubleAnimation { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = -_listFragment.Width }; Storyboard.SetTarget(doubleAnimation2, _listFragment); Storyboard.SetTargetProperty(doubleAnimation2, TranslatePath.Path); _fadeOutStoryboard.Children.Add(doubleAnimation2); // New color animation for _shadowFragment var colorAnimation2 = new ColorAnimation { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = Color.FromArgb(0, 0, 0, 0) }; Storyboard.SetTarget(colorAnimation2, _shadowFragment); Storyboard.SetTargetProperty(colorAnimation2, ColorPath.Path); _fadeOutStoryboard.Children.Add(colorAnimation2); _mainFragment.ManipulationMode = ManipulationModes.All; _mainFragment.ManipulationStarted += mainFragment_ManipulationStarted; _listFragment.ManipulationMode = ManipulationModes.All; _listFragment.ManipulationStarted += listFragment_ManipulationStarted; }
private void shadowFragment_Tapped(object sender, TappedRoutedEventArgs e) { var shadow = new Storyboard(); var doubleAnimation = new DoubleAnimation { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = -_listFragment.Width }; Storyboard.SetTarget(doubleAnimation, _listFragment); Storyboard.SetTargetProperty(doubleAnimation, TranslatePath.Path); shadow.Children.Add(doubleAnimation); var colorAnimation = new ColorAnimation { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = Color.FromArgb(0, 0, 0, 0) }; Storyboard.SetTarget(colorAnimation, _shadowFragment); Storyboard.SetTargetProperty(colorAnimation, ColorPath.Path); shadow.Children.Add(colorAnimation); shadow.Completed += shadow_Completed; shadow.Begin(); }
private void MoveListFragment(double left, Color color) { var s = new Storyboard(); var doubleAnimation = new DoubleAnimation { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = left }; Storyboard.SetTarget(doubleAnimation, _listFragment); Storyboard.SetTargetProperty(doubleAnimation, TranslatePath.Path); s.Children.Add(doubleAnimation); var colorAnimation = new ColorAnimation { Duration = new Duration(new TimeSpan(0, 0, 0, 0, 200)), To = color }; Storyboard.SetTarget(colorAnimation, _shadowFragment); Storyboard.SetTargetProperty(colorAnimation, ColorPath.Path); s.Children.Add(colorAnimation); s.Begin(); }
private void SimpleTextButton_Loaded(object sender, RoutedEventArgs e) { // Unregister for loaded events so we don't do this many times. Loaded -= SimpleTextButton_Loaded; // First, try to get the main root grid. List<DependencyObject> uiElements = new List<DependencyObject>(); UiControlHelpers<Grid>.RecursivelyFindElement(this, ref uiElements); if(uiElements.Count != 1) { throw new Exception("Found too many or too few grids!"); } // Grab it ui_contentRoot = (Grid)uiElements[0]; // Next try to find the text block uiElements.Clear(); UiControlHelpers<TextBlock>.RecursivelyFindElement(this, ref uiElements); if (uiElements.Count != 1) { throw new Exception("Found too many or too few textblocks!"); } // Grab it ui_buttonText = (TextBlock)uiElements[0]; // If the desired text already exists set it if(m_currentButtonText != null) { ui_buttonText.Text = m_currentButtonText; } // Set the normal text color ui_buttonText.Foreground = new SolidColorBrush(m_normalTextColor); // Grab the current accent color m_accentColor = ((SolidColorBrush)Application.Current.Resources["SystemControlBackgroundAccentBrush"]).Color; // Next create our storyboards and animations m_colorStoryboard = new Storyboard(); m_colorAnimation = new ColorAnimation(); m_colorStoryboard.Children.Add(m_colorAnimation); // Set them up. Storyboard.SetTarget(m_colorStoryboard, ui_buttonText); Storyboard.SetTargetProperty(m_colorStoryboard, "(TextBlock.Foreground).(SolidColorBrush.Color)"); m_animateInDuration = new Duration(new TimeSpan(0, 0, 0, 0, 200)); m_animateOutDuration = new Duration(new TimeSpan(0, 0, 0, 0, 400)); // Last add our events to the grid ui_contentRoot.PointerPressed += ContentRoot_PointerPressed; ui_contentRoot.Tapped += ContentRoot_Tapped; ui_contentRoot.PointerCanceled += ContentRoot_PointerCanceled; ui_contentRoot.PointerExited += ContentRoot_PointerExited; ui_contentRoot.PointerReleased += ContentRoot_PointerReleased; }
private void animatecolor() { Storyboard story = new Storyboard(); ColorAnimation animation = new ColorAnimation(); animation.Duration = TimeSpan.FromMilliseconds(850); story.Children.Add(animation); animation.EnableDependentAnimation = true; Storyboard.SetTarget(animation, _bordercolor); Storyboard.SetTargetProperty(animation, "(Border.BorderBrush).(SolidColorBrush.Color)"); animation.To = _datasource.BorderColor; story.Begin(); }
private ColorAnimation CreateInvalidWordColorAnimation() { var animation = new ColorAnimation { AutoReverse = false, EnableDependentAnimation = true, Duration = TimeSpan.FromMilliseconds(1000), To = (Colors.Red) }; return animation; }
private static ColorAnimation CreateColorAnimation(FrameworkElement element, double durationInSeconds, Color finalColor, string property) { ColorAnimation colorAnimation = new ColorAnimation(); colorAnimation.To = finalColor; colorAnimation.Duration = TimeSpan.FromSeconds(durationInSeconds); Storyboard.SetTarget(colorAnimation, element); Storyboard.SetTargetProperty(colorAnimation, property); return colorAnimation; }
private ColorAnimation CreatePolygonTransformAnimation() { //var anim = new animation var animation = new ColorAnimation { AutoReverse = false, EnableDependentAnimation = true, Duration = TimeSpan.FromMilliseconds(4000), To = ColorGenerator.GetRandomColor(ColorScheme.Purple).Color }; animation.EasingFunction = new ExponentialEase(); return animation; }
private ColorAnimation CreatePolygonAnimation() { var animation = new ColorAnimation { AutoReverse = true, // ToDo: Was False RepeatBehavior = RepeatBehavior.Forever, EnableDependentAnimation = true, Duration = TimeSpan.FromMilliseconds(4000), To = ColorGenerator.GetRandomColor(ColorScheme.Purple).Color, EasingFunction = new ExponentialEase() }; return animation; }
private void VisualizeGraph(RainData rainData, bool animated = true) { List<int> pointValues; if (rainData == null || rainData.Points == null) pointValues = new List<int>(); else pointValues = rainData.Points.Take(25).Select(p => p.AdjustedValue).ToList(); while (pointValues.Count < 25) pointValues.Add(pointValues.LastOrDefault()); var path = GraphView.Data as PathGeometry; var graphSize = new Size(GraphContainer.ActualWidth, GraphContainer.ActualHeight); var step = graphSize.Width / Model.Entries; Func<int, double> xForIndex = idx => idx == 0 ? -2 : idx * step; var x = 0; var max = (graphSize.Height / 12.0 * 11.0) - 10; var allZeros = pointValues.Take(Model.Entries + 1).All(p => p == 0); var points = pointValues.Select(v => { var y = allZeros ? max - 20 : Math.Max(1, max - (v * max / 100)); var p = new Point(xForIndex(x), y); x++; return p; }).ToList(); points.Add(new Point(graphSize.Width + 2, points.Last().Y)); points.Add(new Point(graphSize.Width + 2, graphSize.Height + 2)); PathFigure figure; var startPoint = new Point(-2.0, graphSize.Height + 2); if (path == null) { path = new PathGeometry(); figure = new PathFigure() { StartPoint = startPoint, IsClosed = true }; path.Figures.Add(figure); foreach (var p in points) { figure.Segments.Add(new LineSegment() { Point = p }); } GraphView.Data = path; } var entriesAnimated = graphEntries != Model.Entries && graphEntries > 0 && Model.Entries > 0; if (entriesAnimated) UpdateEntriesImage(); var ms300 = TimeSpan.FromMilliseconds(entriesAnimated ? 450 / Math.Abs(Model.Entries - graphEntries) : animated ? 300 : 0); graphEntries = Model.Entries; var storyboard = new Storyboard() { Duration = ms300 }; figure = path.Figures[0]; var anim = new PointAnimation() { Duration = ms300, To = startPoint, FillBehavior = FillBehavior.HoldEnd, EnableDependentAnimation = true }; Storyboard.SetTarget(anim, figure); Storyboard.SetTargetProperty(anim, "StartPoint"); storyboard.Children.Add(anim); for (var i = 0; i < points.Count; ++i) { anim = new PointAnimation() { Duration = ms300, To = points[i], FillBehavior = FillBehavior.HoldEnd, EnableDependentAnimation = true }; Storyboard.SetTarget(anim, figure.Segments[i]); Storyboard.SetTargetProperty(anim, "Point"); storyboard.Children.Add(anim); } var strokeAnim = new ColorAnimation() { Duration = ms300, FillBehavior = FillBehavior.HoldEnd, To = allZeros ? Colors.Transparent : graphStrokeColor, EnableDependentAnimation = true }; Storyboard.SetTarget(strokeAnim, GraphView.Stroke); Storyboard.SetTargetProperty(strokeAnim, "Color"); storyboard.Children.Add(strokeAnim); var fillTopAnim = new ColorAnimation() { Duration = ms300, FillBehavior = FillBehavior.HoldEnd, To = allZeros ? Colors.Black : graphFillFrom, EnableDependentAnimation = true }; Storyboard.SetTarget(fillTopAnim, ((LinearGradientBrush)GraphView.Fill).GradientStops[0]); Storyboard.SetTargetProperty(fillTopAnim, "Color"); storyboard.Children.Add(fillTopAnim); storyboard.Begin(() => GraphView.Data = path); }
private void Init2() { // color var blue = BlueBrush.Color; ColorAnimation colorAnimation = new ColorAnimation() { Duration = TimeSpan.FromMilliseconds(500), To = Color.FromArgb(blue.A, blue.R, blue.G, blue.B), }; Storyboard.SetTarget(colorAnimation, PieSlice); Storyboard.SetTargetProperty(colorAnimation, "(Shape.Fill).(SolidColorBrush.Color)"); ScaleStoryboard.Children.Add(colorAnimation); }
/// <summary> /// Does the text animation on the text box in the Grid. /// Note!! We do this crazy animation stuff so the UI feel responsive. /// It would be ideal to use the SimpleButtonText control but it is too expensive for the virtual list. /// </summary> /// <param name="textBlockContainer"></param> private void AnimateText(FrameworkElement textBlockContainer) { // Make sure it has children if(VisualTreeHelper.GetChildrenCount(textBlockContainer) != 1) { return; } // Try to get the text block TextBlock textBlock = (TextBlock)VisualTreeHelper.GetChild(textBlockContainer, 0); // Return if failed. if(textBlock == null) { return; } // Make a storyboard Storyboard storyboard = new Storyboard(); ColorAnimation colorAnimation = new ColorAnimation(); storyboard.Children.Add(colorAnimation); // Set them up. Storyboard.SetTarget(storyboard, textBlock); Storyboard.SetTargetProperty(storyboard, "(TextBlock.Foreground).(SolidColorBrush.Color)"); storyboard.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 400)); colorAnimation.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 400)); storyboard.BeginTime = new TimeSpan(0, 0, 0, 0, 100); // Set the colors colorAnimation.To = Color.FromArgb(255, 153, 153, 153); colorAnimation.From = ((SolidColorBrush)Application.Current.Resources["SystemControlBackgroundAccentBrush"]).Color; // Set the text to be the accent color textBlock.Foreground = ((SolidColorBrush)Application.Current.Resources["SystemControlBackgroundAccentBrush"]); // And animate it back out. storyboard.Begin(); }
/// <summary> /// Provides animation capability for Color property /// </summary> /// <param name="_Control">Control to be animate</param> /// <param name="_Property">Dependency property to be animate</param> /// <param name="_From">Start animation from color</param> /// <param name="_To">Stop animation at color</param> /// <param name="_TimeSpanInSecond">Time span in second</param> private void StartColorAnimation(DependencyObject _Control, string _Property, Windows.UI.Color _From, Windows.UI.Color _To, double _TimeSpanInSecond = 1) { // Step 1: Create ColorAnimation object and change its properties // ColorAnimation deals with the Windows.UI.Color type so its called ColorAnimation _OpacityAnimation = new ColorAnimation(); _OpacityAnimation.From = _From; _OpacityAnimation.To = _To; _OpacityAnimation.AutoReverse = true; // ebables auto reverse animation // Extra Properties : Uncomment following three lines to see difference TimeSpan _TimeSpan = TimeSpan.FromSeconds(_TimeSpanInSecond); _OpacityAnimation.Duration = _TimeSpan; // _OpacityAnimation.RepeatBehavior = RepeatBehavior.Forever; // Step 2: Create storyboard object and add DoubleAnimation object as its chield Storyboard _Storyboard = new Storyboard(); _Storyboard.Children.Add(_OpacityAnimation); // Step 3: Spesify on which property animation is going to be done by DoubleAnimatin obj Storyboard.SetTargetProperty(_OpacityAnimation, _Property); // Step 4: Spesify on which control story board is to be attached Storyboard.SetTarget(_Storyboard, _Control); // Step 5: Start storyboard and see magic! _Storyboard.Begin(); }