private void AssociatedObject_Loaded(object sender, RoutedEventArgs e) { SlideshowButton.Click += (s, e1) => { var brushAnimation = new BrushAnimation(); brushAnimation.To = Brushes.Black; brushAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(800)); GridLengthAnimation heightAnimation = new GridLengthAnimation(); heightAnimation.To = new GridLength(0); heightAnimation.From = new GridLength(120.0); heightAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); GridLengthAnimation heightAnimation2 = new GridLengthAnimation(); heightAnimation2.To = new GridLength(0); heightAnimation2.From = new GridLength(35.0); heightAnimation2.Duration = new Duration(TimeSpan.FromMilliseconds(500)); heightAnimation.DecelerationRatio = 0.5; heightAnimation2.DecelerationRatio = 0.5; MainGrid.RowDefinitions[MainGrid.RowDefinitions.Count - 1].BeginAnimation(RowDefinition.HeightProperty, heightAnimation); MainGrid.RowDefinitions[0].BeginAnimation(RowDefinition.HeightProperty, heightAnimation2); MainGrid.BeginAnimation(Grid.BackgroundProperty, brushAnimation); RotateButton.Visibility = Visibility.Collapsed; SlideshowButton.Visibility = Visibility.Collapsed; }; }
private void AnimatePanel(bool pIsExtended) { GridLengthAnimation animation = new GridLengthAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(500)), From = new GridLength(Grid.RowDefinitions[1].ActualHeight), FillBehavior = FillBehavior.Stop, AccelerationRatio = 0.5, DecelerationRatio = 0.5 }; if (!pIsExtended) { _contentHeight = ContentPresenter.ActualHeight; animation.To = new GridLength(0); animation.Completed += (sender, args) => { Grid.RowDefinitions[1].Height = new GridLength(0); }; } else { animation.To = new GridLength(_contentHeight); animation.Completed += (sender, args) => { Grid.RowDefinitions[1].Height = GridLength.Auto; }; } Grid.RowDefinitions[1].BeginAnimation(RowDefinition.HeightProperty, animation); }
public void ShowExplorer() { var grid = this.FindName("LeftBar") as Grid; GridLengthAnimation animation = new GridLengthAnimation(); animation.From = new GridLength(this.toMinsize ? grid.ColumnDefinitions[0].Width.Value : 0.0, GridUnitType.Pixel); if (this.toMinsize) { width = grid.ColumnDefinitions[0].Width; animation.To = new GridLength(0.0, GridUnitType.Pixel); } else { animation.To = width; } animation.FillBehavior = FillBehavior.Stop; animation.Duration = new Duration(TimeSpan.FromSeconds(0.25)); grid.ColumnDefinitions[0].Width = animation.To; grid.ColumnDefinitions[0].BeginAnimation(ColumnDefinition.WidthProperty, animation); this.toMinsize = !this.toMinsize; DoubleAnimation oLabelAngleAnimation = new DoubleAnimation(); oLabelAngleAnimation.From = toMinsize ? 180 : 0; oLabelAngleAnimation.To = toMinsize ? 0 : 180; oLabelAngleAnimation.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500)); RotateTransform oTransform = (RotateTransform)rotate.LayoutTransform; oTransform.BeginAnimation(RotateTransform.AngleProperty, oLabelAngleAnimation); }
/// <summary> /// starts the animation if the mouse hovers over the profile picture and the <see cref="HamburgerMenu"/> is not already opened or is not animating /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">mouse information</param> private void ProfileIconContainer_MouseEnter(object sender, MouseEventArgs e) { if (!isOpen && animFinished) { isOpen = true; animFinished = false; GridLengthAnimation gridAnim = new GridLengthAnimation { From = new GridLength(PictureSizeSmall, GridUnitType.Pixel), To = new GridLength(PictureSizeBig, GridUnitType.Pixel), Duration = AnimationDuration }; DoubleAnimation doubleAnim = new DoubleAnimation { From = PictureSizeSmall, To = PictureSizeBig, Duration = AnimationDuration }; gridAnim.Completed += animationCompleted; MainGrid.ColumnDefinitions[0].BeginAnimation(ColumnDefinition.WidthProperty, gridAnim); ProfileImage.BeginAnimation(Ellipse.HeightProperty, doubleAnim); ProfileImage.BeginAnimation(Ellipse.WidthProperty, doubleAnim); ProfileName.Visibility = Visibility.Visible; } }
GridLengthAnimation CreateAnimation(BaseLayoutItem item, DependencyProperty property, GridLength value) { GridLength to = new GridLength(0, GridUnitType.Star); if (maximizedItem != null) { if (maximizedItem == item || maximizedItem.Parent == item) { to = value; } } else { to = value; } GridLengthAnimation a = new GridLengthAnimation { From = (GridLength)item.GetValue(property), To = to, Duration = new TimeSpan(0, 0, 0, 0, 500), FillBehavior = System.Windows.Media.Animation.FillBehavior.Stop }; return(a); }
public static void GridLengthAnimate(this DependencyObject aElement, PropertyPath aPropertyPath, GridLength aFromValue, GridLength aToValue, Duration aDuration, Action aTimeoutAction) { Storyboard storyboard = new Storyboard(); GridLengthAnimation animation = new GridLengthAnimation(); animation.From = aFromValue; animation.To = aToValue; animation.Duration = aDuration; animation.FillBehavior = FillBehavior.Stop; Storyboard.SetTarget(animation, aElement); Storyboard.SetTargetProperty(animation, aPropertyPath); storyboard.Children.Add(animation); EventHandler handler = null; handler = (d, e) => { if (aTimeoutAction != null) { aTimeoutAction.Invoke(); } storyboard.Completed -= handler; storyboard.Remove(); }; storyboard.Completed += handler; storyboard.Begin(); }
/// <summary> /// Erzeugt und startet Storyboard für Reduktion. /// </summary> private void CreateReduceStoryBoard() { GridLengthAnimation column2Reduction = new GridLengthAnimation(); column2Reduction.From = MainGrid.ColumnDefinitions[2].Width; column2Reduction.To = new GridLength(0); column2Reduction.Duration = TimeSpan.FromSeconds(0.4); DoubleAnimation mainGridWidthReduction = new DoubleAnimation(); mainGridWidthReduction.From = MainGrid.Width; mainGridWidthReduction.To = SmallMainGridWidth; mainGridWidthReduction.Duration = new Duration(TimeSpan.FromSeconds(0.4)); DoubleAnimation mainGridWidthReduction2 = new DoubleAnimation(); mainGridWidthReduction2.From = MainGrid.Width; mainGridWidthReduction2.To = SmallMainGridWidth; mainGridWidthReduction2.Duration = new Duration(TimeSpan.FromSeconds(0.4)); ThicknessAnimation moveAnimation = new ThicknessAnimation(); moveAnimation.Duration = TimeSpan.FromSeconds(0.2); moveAnimation.From = new Thickness(0, 0, 0, 0); moveAnimation.To = new Thickness(0, 0, 15, 0); ThicknessAnimation moveAnimation2 = new ThicknessAnimation(); moveAnimation2.Duration = TimeSpan.FromSeconds(0.2); moveAnimation2.From = new Thickness(0, 0, 0, 0); moveAnimation2.To = new Thickness(0, 0, 15, 0); Storyboard reduceStoryboard = new Storyboard(); reduceStoryboard.Children.Add(column2Reduction); reduceStoryboard.Children.Add(mainGridWidthReduction); reduceStoryboard.Children.Add(mainGridWidthReduction2); reduceStoryboard.Children.Add(moveAnimation); reduceStoryboard.Children.Add(moveAnimation2); Storyboard.SetTargetName(column2Reduction, MainGrid.ColumnDefinitions[2].Name); Storyboard.SetTargetProperty(column2Reduction, new PropertyPath(ColumnDefinition.WidthProperty)); Storyboard.SetTargetName(mainGridWidthReduction2, MainGrid.Name); Storyboard.SetTargetProperty(mainGridWidthReduction2, new PropertyPath(Grid.WidthProperty)); Storyboard.SetTargetName(mainGridWidthReduction, this.Name); Storyboard.SetTargetProperty(mainGridWidthReduction, new PropertyPath(System.Windows.Controls.UserControl.WidthProperty)); Storyboard.SetTargetName(moveAnimation, ChangeStateButton.Name); Storyboard.SetTargetName(moveAnimation2, ShowInfosButton.Name); Storyboard.SetTargetProperty(moveAnimation, new PropertyPath(SurfaceButton.MarginProperty)); Storyboard.SetTargetProperty(moveAnimation2, new PropertyPath(SurfaceButton.MarginProperty)); // reduceStoryboard.Completed += new EventHandler(reduceStoryboard_Completed); reduceStoryboard.Begin(this); }
void BeginAnimationToFixedValue(BaseLayoutItem layoutItem, GridLength l, DependencyProperty prop) { GridLengthAnimation a = CreateAnimation(layoutItem, prop, l); a.Completed += (s, e) => { layoutItem.SetValue(prop, a.To); }; layoutItem.BeginAnimation(prop, a); }
private void AnimateGridLength(RowDefinition rowDef, GridLength toLength) { GridLengthAnimation PrecTopAnim = new GridLengthAnimation(); PrecTopAnim.GridUnitType = GridUnitType.Pixel; PrecTopAnim.From = rowDef.Height; PrecTopAnim.To = toLength; PrecTopAnim.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 300)); PrecTopAnim.AccelerationRatio = 0.1; PrecTopAnim.DecelerationRatio = 0.9; rowDef.BeginAnimation(RowDefinition.HeightProperty, PrecTopAnim); }
private void ShowBars() { //Task.Factory.StartNew(() => Execute.OnUIThread(() => { Execute.OnUIThreadAsync(() => { Storyboard storyboard = new Storyboard(); double animTime = 0.4; GridLengthAnimation heightAnimation = new GridLengthAnimation() { From = shellView.bottomBarRow.Height, To = new GridLength(68), Duration = TimeSpan.FromSeconds(animTime) }; heightAnimation.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseInOut }; Storyboard.SetTarget(heightAnimation, shellView.bottomBarRow); Storyboard.SetTargetProperty(heightAnimation, new PropertyPath("Height")); storyboard.Children.Add(heightAnimation); DoubleAnimation topHeightAnimation = new DoubleAnimation() { From = shellView.TopBar.Height, To = 32, Duration = TimeSpan.FromSeconds(animTime) }; topHeightAnimation.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseInOut }; Storyboard.SetTarget(topHeightAnimation, shellView.TopBar); Storyboard.SetTargetProperty(topHeightAnimation, new PropertyPath("Height")); storyboard.Children.Add(topHeightAnimation); DoubleAnimation opacityAnimatiion = new DoubleAnimation() { From = shellView.SelectedFileNameLabel.Opacity, To = 1, Duration = TimeSpan.FromSeconds(animTime * 2) }; Storyboard.SetTarget(opacityAnimatiion, shellView.SelectedFileNameLabel); Storyboard.SetTargetProperty(opacityAnimatiion, new PropertyPath("Opacity")); storyboard.Children.Add(opacityAnimatiion); DoubleAnimation opacityProgressAnimation = new DoubleAnimation() { From = shellView.SelectedFileNameLabel.Opacity, To = 1, Duration = TimeSpan.FromSeconds(animTime) }; Storyboard.SetTarget(opacityProgressAnimation, shellView.VideoProgressBar); Storyboard.SetTargetProperty(opacityProgressAnimation, new PropertyPath("Opacity")); storyboard.Children.Add(opacityProgressAnimation); storyboard.Begin(); }); //})); }
public static void GridSplitterOpeningBounce(this DefinitionBase rowColDefinition, bool opening = false, int openToSize = 0, Action <bool> afterCompleted = null) { if (rowColDefinition == null) { return; //for when events fire before everything is initialized } var isRow = (rowColDefinition.GetType() == typeof(RowDefinition)); Storyboard story; if (!GridSplitterPositions.TryGetValue(rowColDefinition, out story)) { var animation = new GridLengthAnimation { To = new GridLength(openToSize), Duration = new TimeSpan(0, 0, 1) }; Storyboard.SetTarget(animation, rowColDefinition); Storyboard.SetTargetProperty(animation, new PropertyPath(isRow ? "Height" : "Width")); GridSplitterPositions[rowColDefinition] = story = new Storyboard(); story.Children.Add(animation); if (afterCompleted != null) { story.Completed += (s, e) => afterCompleted(opening); } } var currentPositionProperty = isRow ? RowDefinition.HeightProperty : ColumnDefinition.WidthProperty; if (opening) { //only bugger with popping open if not already opened by user if (((GridLength)rowColDefinition.GetValue(currentPositionProperty)).Value <= 0.0) { story.Begin(); } } else { story.Stop(); //save the current position in the animation's "To" property so it opens back to where it was before we closed it var current = (GridLength)rowColDefinition.GetValue(currentPositionProperty); if (current.GridUnitType != GridUnitType.Star && current.Value > 0) { ((GridLengthAnimation)story.Children[0]).To = current; } rowColDefinition.SetValue(currentPositionProperty, new GridLength(0, GridUnitType.Pixel)); } }
private void AnimateToSize(double left, double top, double height, double width) { var heightAnim = new GridLengthAnimation(headerRowDefinition.Height, new GridLength(height), new Duration(TimeSpan.FromMilliseconds(500))); var widthAnim = new GridLengthAnimation(keyBorderColumnDefinition.Width, new GridLength(width), new Duration(TimeSpan.FromMilliseconds(500))); Storyboard.SetTargetName(heightAnim, "headerRowDefinition"); Storyboard.SetTargetProperty(heightAnim, new PropertyPath(RowDefinition.HeightProperty)); Storyboard.SetTargetName(widthAnim, "keyBorderColumnDefinition"); Storyboard.SetTargetProperty(widthAnim, new PropertyPath(ColumnDefinition.WidthProperty)); var story2 = new Storyboard(); story2.Children.Add(heightAnim); story2.Children.Add(widthAnim); story2.Begin(this); }
private static void OnAttachGridAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { ColumnDefinition columndefinition = e.NewValue as ColumnDefinition; Button btn = d as Button; btn.Click += (sender, routedeventargs) => { GridLengthAnimation animation = new GridLengthAnimation(); animation.From = columndefinition.Width; animation.To = new GridLength(0.3, GridUnitType.Star); animation.Duration = new Duration(TimeSpan.FromSeconds(0.5)); columndefinition.BeginAnimation(ColumnDefinition.WidthProperty, animation); }; } catch { } }
public MenuComponent(Grid grid, MenuSettings settings) { this.grid = grid; this.settings = settings; shouldChangeColumn = settings.Column > -1; shouldChangeRow = settings.Row > -1; if (shouldChangeColumn) { columnAnim = new GridLengthAnimation(settings.InitialPosition.X, settings.TargetPosition.X, settings.Duration); columnAnimBack = new GridLengthAnimation(settings.TargetPosition.X, settings.InitialPosition.X, settings.Duration); } if (shouldChangeRow) { rowAnim = new GridLengthAnimation(settings.InitialPosition.Y, settings.TargetPosition.Y, settings.Duration); rowAnimBack = new GridLengthAnimation(settings.TargetPosition.Y, settings.InitialPosition.Y, settings.Duration); } }
public MasterDetailView() { this.InitializeComponent(); this.IsVisibleChanged += IsVisibleChangedEventHandler; this.SizeChanged += SizeChangedEventHandler; detailGridSplitter.DragStarted += DetailGridSplitterDragStartedEventHandler; detailGridSplitter.DragCompleted += DetailGridSplitterDragCompletedEventHandler; prevGridLength = new GridLength(0, GridUnitType.Pixel); animation = new GridLengthAnimation(); animation.Completed += AnimationCompletedEventHandler; masterWorkspace.SmartPartClosed += (s, e) => { Presenter.Close(); }; }
private void ShowAdvanceSearchControl(DoubleAnimationEventArgs args) { enabledSaveSplitPosition = args.To > 0; int commonTime = (LeftColumn.ActualWidth - args.To) > 0 ? 300 : 200; int time = Math.Abs((int)((LeftColumn.ActualWidth - args.To) * commonTime / 110)); if (Math.Abs(lastWindth) < Epsilon) { lastWindth = args.To; } double to; if (Math.Abs(args.To) < Epsilon) { lastWindth = LeftColumn.ActualWidth; to = 0; } else { to = lastWindth; } var animation = new GridLengthAnimation { From = new GridLength(LeftColumn.ActualWidth, GridUnitType.Pixel), To = new GridLength(to, GridUnitType.Pixel), Duration = TimeSpan.FromMilliseconds(time) }; animation.Completed += delegate { SetSplitter(args.To); if (args.To > 0) { SaveSplitterPosition(); } }; LeftColumn.BeginAnimation(ColumnDefinition.WidthProperty, animation); }
public EmployeeManagePanel() { InitializeComponent(); var fun = new CubicEase() { EasingMode = EasingMode.EaseInOut }; _expandAnimation = new GridLengthAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(300)), FillBehavior = FillBehavior.Stop, EasingFunction = fun }; _collapseAnimation = new GridLengthAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(300)), To = new GridLength(0), EasingFunction = fun }; _collapseAnimation.Completed += _collapseAnimation_Completed; _expandAnimation.Completed += _expandAnimation_Completed; _lastWidth = rightColumn.Width; this.Button_Click(null, null); }
public static void GridSplitterOpeningBounce(DefinitionBase RowColDefinition, int InitialSize, bool Opening) { if (RowColDefinition == null) { return; //for when events fire before everything is initialized } bool IsRow = (RowColDefinition.GetType() == typeof(RowDefinition)); Storyboard story; if (!GridSplitterPositions.TryGetValue(RowColDefinition, out story)) { GridLengthAnimation animation = new GridLengthAnimation(); animation.To = new GridLength(InitialSize); animation.Duration = new TimeSpan(0, 0, 1); Storyboard.SetTarget(animation, RowColDefinition); Storyboard.SetTargetProperty(animation, new PropertyPath(IsRow ? "Height" : "Width")); GridSplitterPositions[RowColDefinition] = story = new Storyboard(); story.Children.Add(animation); } if (Opening) { story.Begin(); } else { story.Stop(); DependencyProperty CurrentPositionProperty = IsRow ? RowDefinition.HeightProperty : ColumnDefinition.WidthProperty; //save the current position in the animation's "To" property so it opens back to where it was before we closed it (story.Children[0] as GridLengthAnimation).To = (GridLength)RowColDefinition.GetValue(CurrentPositionProperty); RowColDefinition.SetValue(CurrentPositionProperty, new GridLength(0, GridUnitType.Pixel)); } }
private void PlayFile(string fileName, double startFrom = 0) { string prevFile = treeGroups.FindPrevFile(fileName); if (_dashCamFileInfo != null && prevFile != _dashCamFileInfo.FrontFileName) { MainMap.SetRouteAndCar(null); //reset route } gpsInfo.UpdateInfo(null, -1); //reset GPS Info control _dashCamFileInfo = new DashCamFileInfo(fileName, Settings.Default.SpeedUnits); txtFileName.Text = _dashCamFileInfo.FrontFileName; playerF.Open(_dashCamFileInfo.FrontFileName, playerF.Volume); playerR.Open(_dashCamFileInfo.BackFileName, 0); Settings.Default.LastFileName = playerF.FileName; Settings.Default.Save(); graphSpeedInfo.SetGpsInfo(_dashCamFileInfo.GpsInfo); if (_dashCamFileInfo.HasGpsInfo) { MainMap.SetRouteAndCar(_dashCamFileInfo); UpdateGpsInfo(); if (_bMapWasCollapsed)// && mapColumn.Width.Value < 300) { _bMapWasCollapsed = false; MainMap.Zoom = 16; //GridLengthAnimation.AnimateColumn(mapColumn, mapColumn.Width, 500); //select file AFTER map is expanded GridLengthAnimation.AnimateRow(rowMaps, new GridLength(5, GridUnitType.Star), 500, () => treeGroups.SelectFile(fileName)); GridLengthAnimation.AnimateRow(rowGpsInfo, new GridLength(2, GridUnitType.Star)); GridLengthAnimation.AnimateRow(rowSpeedGraph, new GridLength(1.3, GridUnitType.Star)); } } else //no GPS info { //MainMap.Position = new PointLatLng(first.Latitude, first.Longitude); if (!_bMapWasCollapsed)// && mapColumn.Width.Value > 300) { _bMapWasCollapsed = true; MainMap.Zoom = 2; GridLengthAnimation.AnimateRow(rowMaps, new GridLength(0)); GridLengthAnimation.AnimateRow(rowGpsInfo, new GridLength(0)); GridLengthAnimation.AnimateRow(rowSpeedGraph, new GridLength(0)); } } if (File.Exists(_dashCamFileInfo.BackFileName)) { if (_bRearViewWasCollapsed) { _bRearViewWasCollapsed = false; GridLengthAnimation.AnimateRow(rowFrontView, new GridLength(5, GridUnitType.Star)); GridLengthAnimation.AnimateRow(rowRearView, new GridLength(3, GridUnitType.Star)); } } else { if (!_bRearViewWasCollapsed) { _bRearViewWasCollapsed = true; GridLengthAnimation.AnimateRow(rowFrontView, new GridLength(5, GridUnitType.Star)); GridLengthAnimation.AnimateRow(rowRearView, new GridLength(0)); } } treeGroups.SelectFile(fileName); playerF.Play(); playerR.Play(); }
void CollapseColumn(GridSplitter splitter, ColumnDefinition def, string content) { // Ignore collapse if popup is opened if (PopupManager.ActivePopup != null) { return; } int collapsed = 0; // Count the number of collapsed items (exclusing collapseView and rockScroll) for (int i = 0; i < OverviewContainerRootGrid.ColumnDefinitions.Count - 2; i++) { if (OverviewContainerRootGrid.ColumnDefinitions[i].Width.Value == 0) { collapsed++; } } // Only allowed to collapse when there are at least two columns which have Width > 0 if (collapsed >= OverviewContainerRootGrid.ColumnDefinitions.Count - 3) { return; } GridColumnSizeHelper.SetPreviousGridLength(def, def.Width); //Start Collapse Column Animation, only when the column Width != 0 if (def.Width != new GridLength(0)) { Storyboard CollapseColumnGrid = (Storyboard)FindResource("CollapseColumn"); Storyboard.SetTarget(CollapseColumnGrid, def); GridLengthAnimation gla = CollapseColumnGrid.Children[0] as GridLengthAnimation; gla.From = def.Width; gla.To = new GridLength(0); CollapseColumnGrid.Begin(this); } if (splitter != null) { splitter.IsEnabled = false; } collapseView.AddCollapsedView(def, content, delegate { //Start Expand Column Animation, only when the column Width = 0 if (def.Width == new GridLength(0)) { def.Width = GridColumnSizeHelper.GetPreviousGridLength(def); GridLength previousWidth = def.Width; def.Width = new GridLength(0); Storyboard ExpandColumnGrid = (Storyboard)FindResource("CollapseColumn"); Storyboard.SetTarget(ExpandColumnGrid, def); GridLengthAnimation gla = ExpandColumnGrid.Children[0] as GridLengthAnimation; gla.From = new GridLength(0); gla.To = previousWidth; ExpandColumnGrid.Begin(this); } if (splitter != null) { splitter.IsEnabled = true; } }); }
public void SetNewState(int columnIndex, ColumnState stateAffected, bool useAnimation) { bool[] modeEnabledNew = new bool[modeEnabled.Length]; int modePoweredNew = modePowered; modeEnabled.CopyTo(modeEnabledNew, 0); if (stateAffected == ColumnState.Visibility) { // Enable/Disable modeEnabledNew[columnIndex] = !modeEnabledNew[columnIndex]; if (!modeEnabledNew[columnIndex] && modePoweredNew == columnIndex) { modePoweredNew = -1; } } else if (stateAffected == ColumnState.Powered) { // Set/unset powered modePoweredNew = modePoweredNew == columnIndex ? -1 : columnIndex; if (!modeEnabled[columnIndex] && modePoweredNew == columnIndex) { modeEnabledNew[columnIndex] = true; } } else { for (int i = 0; i < modeEnabledNew.Length; i++) { modeEnabledNew[i] = true; } modePoweredNew = -1; } double totalDefaultSize = defaultColumnSizes.Sum(); double columnsTotalSize = columns.Sum(c => c.Width.Value); // Normalize column sizes to fit totalSize. for (int i = 0; i < columns.Length; i++) { columns[i].MinWidth = 0; if (columnsTotalSize == 0 || totalDefaultSize == 0) { columns[i].Width = new GridLength(0); } else { columns[i].Width = new GridLength(totalDefaultSize / columnsTotalSize * columns[i].Width.Value, GridUnitType.Star); } } double[] columnsNewSize = new double[3]; for (int i = 0; i < columnsNewSize.Length; i++) { columnsNewSize[i] = modeEnabledNew[i] ? (defaultColumnSizes[i] * (modePoweredNew == i ? 3f : 1f)) : 0f; } ; // Animate columns whose enabled or powered state changes. for (int i = 0; i < columnsNewSize.Length; i++) { if (modeEnabled[i] || modeEnabledNew[i]) { var col = columns[i]; double newSize = columnsNewSize[i]; if (useAnimation) { GridLengthAnimation animation = new GridLengthAnimation(); animation.From = col.Width; animation.To = new GridLength(newSize, GridUnitType.Star); animation.Duration = new Duration(TimeSpan.FromMilliseconds(animationDuration)); animation.FillBehavior = FillBehavior.Stop; // Fixes GridSplitter not working after animation (first comment of https://stackoverflow.com/a/16844818/8577979) animation.Completed += (s, _) => { col.Width = new GridLength(newSize, GridUnitType.Star); }; if (modeEnabled[i] != modeEnabledNew[i] && defaultColumnMinSizes[i] > 0f) { DoubleAnimation minSizeAnimation = new DoubleAnimation( modeEnabledNew[i] ? defaultColumnMinSizes[i] : 0f, new Duration(TimeSpan.FromMilliseconds(animationDuration))); col.BeginAnimation(ColumnDefinition.MinWidthProperty, minSizeAnimation); } col.BeginAnimation(ColumnDefinition.WidthProperty, animation); } else { col.MinWidth = modeEnabledNew[i] ? defaultColumnMinSizes[i] : 0f; col.Width = new GridLength(newSize, GridUnitType.Star); } } } modeEnabled = modeEnabledNew; modePowered = modePoweredNew; //ColumnGridSplitterLeft.Visibility = (modeEnabled[0] && (modeEnabled[1] || modeEnabled[2])) ? Visibility.Visible : Visibility.Collapsed; //ColumnGridSplitterRight.Visibility = (modeEnabled[2] && modeEnabled[1]) ? Visibility.Visible : Visibility.Collapsed; }
private void Border_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { GridLengthAnimation glaLeft = new GridLengthAnimation(); GridLengthAnimation glaRight = new GridLengthAnimation(); DoubleAnimation rotation = new DoubleAnimation(); DoubleAnimation appear = new DoubleAnimation(); DoubleAnimation hide = new DoubleAnimation(); glaLeft.Duration = TimeSpan.FromMilliseconds(500); glaLeft.BeginTime = TimeSpan.FromMilliseconds(500); glaRight.Duration = TimeSpan.FromMilliseconds(500); glaRight.BeginTime = TimeSpan.FromMilliseconds(500); rotation.Duration = TimeSpan.FromMilliseconds(500); rotation.FillBehavior = FillBehavior.HoldEnd; rotation.BeginTime = TimeSpan.FromMilliseconds(500); appear.Duration = TimeSpan.FromMilliseconds(250); appear.FillBehavior = FillBehavior.HoldEnd; appear.BeginTime = TimeSpan.FromMilliseconds(500); appear.BeginTime = TimeSpan.FromMilliseconds(750); appear.From = 0; appear.To = 1; hide.Duration = TimeSpan.FromMilliseconds(250); hide.FillBehavior = FillBehavior.HoldEnd; hide.From = 1; hide.To = 0; if (IsLeftOpen == false) { //To SignIn glaLeft.From = new GridLength(1, GridUnitType.Star); glaLeft.To = new GridLength(0, GridUnitType.Star); glaRight.From = new GridLength(0, GridUnitType.Star); glaRight.To = new GridLength(1, GridUnitType.Star); rotation.From = 225; rotation.To = 45; foreach (Border border in Container.Children) { if (border.Tag?.ToString() == "SignIn") { border.BeginAnimation(OpacityProperty, hide); } else if (border.Tag?.ToString() == "SignUp") { border.BeginAnimation(OpacityProperty, appear); } } } else { //To SignUp glaLeft.From = new GridLength(0, GridUnitType.Star); glaLeft.To = new GridLength(1, GridUnitType.Star); glaRight.From = new GridLength(1, GridUnitType.Star); glaRight.To = new GridLength(0, GridUnitType.Star); rotation.From = 45; rotation.To = 225; foreach (Border border in Container.Children) { if (border.Tag?.ToString() == "SignIn") { border.BeginAnimation(OpacityProperty, appear); } else if (border.Tag?.ToString() == "SignUp") { border.BeginAnimation(OpacityProperty, hide); } } } Arrow.BeginAnimation(RotateTransform.AngleProperty, rotation); SignInColumn.BeginAnimation(ColumnDefinition.WidthProperty, glaLeft); SignUpColumn.BeginAnimation(ColumnDefinition.WidthProperty, glaRight); IsLeftOpen = !IsLeftOpen; }
/// <summary> /// Begins adjustable animation for a GridlengthAnimation. /// Holds animation end value without Holding it. i.e. Allows it to change after animation without resetting it. Should be possible in WPF...maybe it is. /// </summary> /// <param name="element">Element to start animation on.</param> /// <param name="dp">Property to animate.</param> /// <param name="anim">Animation to perform. GridLengthAnimation only for now.</param> public static void BeginAdjustableAnimation(this ContentElement element, DependencyProperty dp, GridLengthAnimation anim) { element.BeginAdjustableAnimation(dp, anim, anim.To); }
/// <summary> /// Begins an animation that automatically sets final value to be held. Used with FillType.Stop rather than default FillType.Hold. /// </summary> /// <param name="element">Content Element to animate.</param> /// <param name="anim">Animation to use on element.</param> /// <param name="dp">Property of element to animate using anim.</param> /// <param name="To">Final value of element's dp.</param> public static void BeginAdjustableAnimation(this ContentElement element, DependencyProperty dp, GridLengthAnimation anim, object To) { if (dp.IsValidType(To)) { element.SetValue(dp, To); element.BeginAnimation(dp, anim); } else { throw new Exception("To object value passed is of the wrong Type. Given: " + To.GetType() + " Expected: " + dp.PropertyType); } }
private void DisplayFullScreenTimeOfDay() { var sb = new Storyboard(); // fade out timer... var fadeOutTimer = new DoubleAnimation(1.0, 0.0, TimeSpan.FromMilliseconds(400)); Storyboard.SetTarget(fadeOutTimer, TimerPanel); Storyboard.SetTargetProperty(fadeOutTimer, new PropertyPath(OpacityProperty)); fadeOutTimer.BeginTime = TimeSpan.Zero; // fade out clock... var fadeOutClock = new DoubleAnimation(1.0, 0.0, TimeSpan.FromMilliseconds(400)); Storyboard.SetTarget(fadeOutClock, ClockPanel); Storyboard.SetTargetProperty(fadeOutClock, new PropertyPath(OpacityProperty)); fadeOutClock.BeginTime = TimeSpan.Zero; GridLengthAnimation rowHeightAdjust1 = null; GridLengthAnimation rowHeightAdjust2 = null; var model = (TimerOutputWindowViewModel)DataContext; switch (model.FullScreenClockMode) { case FullScreenClockMode.Analogue: rowHeightAdjust1 = new GridLengthAnimation { From = new GridLength(100, GridUnitType.Star), To = new GridLength(100, GridUnitType.Star), BeginTime = TimeSpan.FromMilliseconds(500) }; Storyboard.SetTarget(rowHeightAdjust1, ClockGrid.RowDefinitions[0]); Storyboard.SetTargetProperty(rowHeightAdjust1, new PropertyPath(RowDefinition.HeightProperty)); rowHeightAdjust2 = new GridLengthAnimation { From = new GridLength(0, GridUnitType.Star), To = new GridLength(0, GridUnitType.Star), BeginTime = TimeSpan.FromMilliseconds(500) }; Storyboard.SetTarget(rowHeightAdjust2, ClockGrid.RowDefinitions[1]); Storyboard.SetTargetProperty(rowHeightAdjust2, new PropertyPath(RowDefinition.HeightProperty)); break; case FullScreenClockMode.Digital: rowHeightAdjust1 = new GridLengthAnimation { From = new GridLength(0, GridUnitType.Star), To = new GridLength(0, GridUnitType.Star), BeginTime = TimeSpan.FromMilliseconds(500) }; Storyboard.SetTarget(rowHeightAdjust1, ClockGrid.RowDefinitions[0]); Storyboard.SetTargetProperty(rowHeightAdjust1, new PropertyPath(RowDefinition.HeightProperty)); rowHeightAdjust2 = new GridLengthAnimation { From = new GridLength(100, GridUnitType.Star), To = new GridLength(100, GridUnitType.Star), BeginTime = TimeSpan.FromMilliseconds(500) }; Storyboard.SetTarget(rowHeightAdjust2, ClockGrid.RowDefinitions[1]); Storyboard.SetTargetProperty(rowHeightAdjust2, new PropertyPath(RowDefinition.HeightProperty)); break; } // change clock panel to use colspan 2... var changeColSpan = new Int32Animation(1, 2, TimeSpan.Zero); Storyboard.SetTarget(changeColSpan, ClockPanel); Storyboard.SetTargetProperty(changeColSpan, new PropertyPath(Grid.ColumnSpanProperty)); changeColSpan.BeginTime = TimeSpan.FromMilliseconds(500); // fade in the clock panel again... var fadeInClock = new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(400)); Storyboard.SetTarget(fadeInClock, ClockPanel); Storyboard.SetTargetProperty(fadeInClock, new PropertyPath(OpacityProperty)); fadeInClock.BeginTime = TimeSpan.FromMilliseconds(1000); sb.Children.Add(fadeOutTimer); sb.Children.Add(fadeOutClock); if (rowHeightAdjust1 != null) { sb.Children.Add(rowHeightAdjust1); } if (rowHeightAdjust2 != null) { sb.Children.Add(rowHeightAdjust2); } sb.Children.Add(changeColSpan); sb.Children.Add(fadeInClock); sb.Begin(); }
private void DisplaySplitScreen() { var sb = new Storyboard(); // fade out clock panel... var fadeOutClock = new DoubleAnimation(1.0, 0.0, TimeSpan.FromMilliseconds(400)); Storyboard.SetTarget(fadeOutClock, ClockPanel); Storyboard.SetTargetProperty(fadeOutClock, new PropertyPath(OpacityProperty)); fadeOutClock.BeginTime = TimeSpan.Zero; // row heights... GridLengthAnimation rowHeightAdjust1 = new GridLengthAnimation { From = new GridLength(75, GridUnitType.Star), To = new GridLength(75, GridUnitType.Star), BeginTime = TimeSpan.FromMilliseconds(500) }; Storyboard.SetTarget(rowHeightAdjust1, ClockGrid.RowDefinitions[0]); Storyboard.SetTargetProperty(rowHeightAdjust1, new PropertyPath(RowDefinition.HeightProperty)); GridLengthAnimation rowHeightAdjust2 = new GridLengthAnimation { From = new GridLength(25, GridUnitType.Star), To = new GridLength(25, GridUnitType.Star), BeginTime = TimeSpan.FromMilliseconds(500) }; Storyboard.SetTarget(rowHeightAdjust2, ClockGrid.RowDefinitions[1]); Storyboard.SetTargetProperty(rowHeightAdjust2, new PropertyPath(RowDefinition.HeightProperty)); // restrict clock panel to column 0... var changeColSpan = new Int32Animation(2, 1, TimeSpan.Zero); Storyboard.SetTarget(changeColSpan, ClockPanel); Storyboard.SetTargetProperty(changeColSpan, new PropertyPath(Grid.ColumnSpanProperty)); changeColSpan.BeginTime = TimeSpan.FromMilliseconds(500); // fade in the clock panel again... var fadeInClock = new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(400)); Storyboard.SetTarget(fadeInClock, ClockPanel); Storyboard.SetTargetProperty(fadeInClock, new PropertyPath(OpacityProperty)); fadeInClock.BeginTime = TimeSpan.FromMilliseconds(1000); // and fade in the timer... var fadeInTimer = new DoubleAnimation(0.0, 1.0, TimeSpan.FromMilliseconds(400)); Storyboard.SetTarget(fadeInTimer, TimerPanel); Storyboard.SetTargetProperty(fadeInTimer, new PropertyPath(OpacityProperty)); fadeInTimer.BeginTime = TimeSpan.FromMilliseconds(1000); sb.Children.Add(fadeOutClock); sb.Children.Add(rowHeightAdjust1); sb.Children.Add(rowHeightAdjust2); sb.Children.Add(changeColSpan); sb.Children.Add(fadeInClock); sb.Children.Add(fadeInTimer); sb.Begin(); }
public static void GridSplitterOpeningBounce(this DefinitionBase rowColDefinition, bool opening = false, int openToSize = 0, Action<bool> afterCompleted = null) { if (rowColDefinition == null) return; //for when events fire before everything is initialized var isRow = (rowColDefinition.GetType() == typeof(RowDefinition)); Storyboard story; if (!GridSplitterPositions.TryGetValue(rowColDefinition, out story)) { var animation = new GridLengthAnimation {To = new GridLength(openToSize), Duration = new TimeSpan(0, 0, 1)}; Storyboard.SetTarget(animation, rowColDefinition); Storyboard.SetTargetProperty(animation, new PropertyPath(isRow ? "Height" : "Width")); GridSplitterPositions[rowColDefinition] = story = new Storyboard(); story.Children.Add(animation); if (afterCompleted != null) story.Completed += (s,e) => afterCompleted(opening); } var currentPositionProperty = isRow ? RowDefinition.HeightProperty : ColumnDefinition.WidthProperty; if (opening) { //only bugger with popping open if not already opened by user if (((GridLength)rowColDefinition.GetValue(currentPositionProperty)).Value <= 0.0) story.Begin(); } else { story.Stop(); //save the current position in the animation's "To" property so it opens back to where it was before we closed it var current = (GridLength)rowColDefinition.GetValue(currentPositionProperty); if (current.GridUnitType != GridUnitType.Star && current.Value > 0) ((GridLengthAnimation) story.Children[0]).To = current; rowColDefinition.SetValue(currentPositionProperty, new GridLength(0, GridUnitType.Pixel)); } }