public async Task Start_WithCallback_CompositionOnly() { await App.DispatcherQueue.EnqueueAsync(async() => { var button = new Button(); var grid = new Grid() { Children = { button } }; await SetTestContentAsync(grid); var tcs = new TaskCompletionSource <object>(); AnimationBuilder.Create() .Scale( to: new Vector3(1.2f, 1, 1), delay: TimeSpan.FromMilliseconds(400)) .Opacity( to: 0.7, duration: TimeSpan.FromSeconds(1)) .Start(button, () => tcs.SetResult(null)); await tcs.Task; // Note: we're just testing Scale and Opacity here as they're among the Visual properties that // are kept in sync on the Visual object after an animation completes, so we can use their // values below to check that the animations have run correctly. There is no particular reason // why we chose these two animations specifically other than this. For instance, checking // Visual.TransformMatrix.Translation or Visual.Offset after an animation targeting those // properties doesn't correctly report the final value and remains out of sync ¯\_(ツ)_/¯ Assert.AreEqual(button.GetVisual().Scale, new Vector3(1.2f, 1, 1)); Assert.AreEqual(button.GetVisual().Opacity, 0.7f); }); }
public async Task SetAndAnimateTranslation() { await App.DispatcherQueue.EnqueueAsync(async() => { var button = new Button(); var grid = new Grid() { Children = { button } }; VisualExtensions.SetTranslation(button, "80, 20, 0"); await SetTestContentAsync(grid); await AnimationBuilder.Create() .Translation(to: new Vector3(11, 22, 0)) .StartAsync(button); var success = button.GetVisual().Properties.TryGetVector3("Translation", out Vector3 translation); Assert.AreEqual(success, CompositionGetValueStatus.Succeeded); Assert.AreEqual(translation, new Vector3(11, 22, 0)); string text = VisualExtensions.GetTranslation(button); Assert.AreEqual(text, new Vector3(11, 22, 0).ToString()); }); }
private async void OnLoaded(object sender, RoutedEventArgs e) { //await AnimationBuilder.Create().Opacity(to: 0, duration: TimeSpan.FromSeconds(0.001)).StartAsync(LayoutRoot); await AnimationBuilder.Create().Opacity(from: 0.01, to: 1, duration: TimeSpan.FromSeconds(1.5)).StartAsync(LayoutRoot); ShowTextShimming(); }
private void ItemContainer_PointerExited(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { var panel = (sender as FrameworkElement).FindDescendant <DropShadowPanel>(); if (panel != null) { AnimationBuilder.Create().Opacity(0, duration: TimeSpan.FromMilliseconds(1200)).Start(panel); AnimationBuilder.Create().Scale(1, duration: TimeSpan.FromMilliseconds(1200)).Start((UIElement)panel.Parent); } }
//--------------------------------------------------------Events:---------------------------------------------------------------------\\ #region --Events-- private void SettingsSelectionControl_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (!(DeviceFamilyHelper.IsMouseInteractionMode() && sender is SettingsSelectionLargeControl settingsSelection)) { return; } LastPopUpElement = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(settingsSelection) as FrameworkElement) as FrameworkElement; Canvas.SetZIndex(LastPopUpElement, 10); AnimationBuilder.Create().Scale(to: 1.05, easingType: EasingType.Sine).Start(LastPopUpElement); }
private void OnSelectionButtonPointerExited(object sender, PointerRoutedEventArgs e) { if (LastPopUpElement is null) { return; } Canvas.SetZIndex(LastPopUpElement, 0); AnimationBuilder.Create().Scale(to: new Vector2(1.0f), easingType: EasingType.Sine).Start(LastPopUpElement); LastPopUpElement = null; }
//--------------------------------------------------------Events:---------------------------------------------------------------------\\ #region --Events-- private void OnSelectionButtonPointerEntered(object sender, PointerRoutedEventArgs e) { if (!(DeviceFamilyHelper.IsMouseInteractionMode() && sender is SettingsSelectionLargeControl settingsSelection)) { return; } LastPopUpElement = settingsSelection; Canvas.SetZIndex(LastPopUpElement, 10); AnimationBuilder.Create().Scale(to: new Vector2(1.05f), easingType: EasingType.Sine).Start(LastPopUpElement); }
private void SettingsSelectionControl_PointerExited(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (LastPopUpElement is null) { return; } Canvas.SetZIndex(LastPopUpElement, 0); AnimationBuilder.Create().Scale(to: 1.0, easingType: EasingType.Sine).Start(LastPopUpElement); LastPopUpElement = null; }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); _container = GetTemplateChild("ContentContainer") as FrameworkElement; AnimationBuilder.Create() .Opacity() .NormalizedKeyFrames(b => b .KeyFrame(0, 0.0, easingType: EasingType.Linear) ) .Start(_container); }
private void ItemContainer_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse) { var panel = (sender as FrameworkElement).FindDescendant <DropShadowPanel>(); if (panel != null) { panel.Visibility = Visibility.Visible; AnimationBuilder.Create().Opacity(1, duration: TimeSpan.FromMilliseconds(600)).Start(panel); AnimationBuilder.Create().Scale(1.1, duration: TimeSpan.FromMilliseconds(600)).Start((UIElement)panel.Parent); } } }
public async Task HideAsync(bool success) { if (success) { ImageEditDone?.Invoke(this, new ImageEditDoneEventArgs(VIEW_MODEL.MODEL.OriginalImage)); } else { ImageEditDone?.Invoke(this, new ImageEditDoneEventArgs()); } await AnimationBuilder.Create().Translation(Axis.Y, contentHeight, 0, TimeSpan.FromMilliseconds(500), easingMode: EasingMode.EaseInOut).StartAsync(this); Visibility = Visibility.Collapsed; }
void ResetAnimation() { lock (_AnimationCtsLock) { if (_AnimationCts != null) { _AnimationCts.Cancel(); _AnimationCts.Dispose(); } _AnimationCts = new CancellationTokenSource(); } var ct = _AnimationCts.Token; if (Content != null) { if (IsAutoHideEnabled) { var ab = AnimationBuilder.Create() .Opacity(layer: FrameworkLayer.Xaml) .TimedKeyFrames(b => b .KeyFrame(FadeInDuration, 1.0, easingType: EasingType.Linear) .KeyFrame(DisplayDuration + FadeInDuration, 1.0, easingType: EasingType.Linear) .KeyFrame(DisplayDuration + FadeInDuration + FadeOutDuration, 0.0, easingType: EasingType.Linear) ); ab.StartAsync(_container, ct); } else { var ab = AnimationBuilder.Create() .Opacity() .TimedKeyFrames(b => b .KeyFrame(FadeInDuration, 1.0, easingType: EasingType.Linear) ); ab.StartAsync(_container, ct); } } else { var ab = AnimationBuilder.Create() .Opacity() .TimedKeyFrames(b => b .KeyFrame(FadeOutDuration, 0.0, easingType: EasingType.Linear) ); ab.StartAsync(_container, ct); } }
private void Hide() { if (this.AssociatedObject == null) { return; } StopAnimation(); if (IsAnimationEnabled) { var ct = CreateAnimationCancellationToken(); _ = AnimationBuilder.Create().Opacity(0.0).StartAsync(this.AssociatedObject, ct) .ContinueWith(prevTask => HideAnimation_Completed()); } else { AssociatedObject.Opacity = 0.0; } }
public async Task Start_WithCallback_XamlOnly() { await App.DispatcherQueue.EnqueueAsync(async() => { var button = new Button(); var grid = new Grid() { Children = { button } }; await SetTestContentAsync(grid); var tcs = new TaskCompletionSource <object>(); AnimationBuilder.Create() .Translation( to: new Vector2(80, 20), layer: FrameworkLayer.Xaml) .Scale( to: new Vector2(1.2f, 1), delay: TimeSpan.FromMilliseconds(400), layer: FrameworkLayer.Xaml) .Opacity( to: 0.7, duration: TimeSpan.FromSeconds(1), layer: FrameworkLayer.Xaml) .Start(button, () => tcs.SetResult(null)); await tcs.Task; CompositeTransform transform = button.RenderTransform as CompositeTransform; Assert.IsNotNull(transform); Assert.AreEqual(transform.TranslateX, 80); Assert.AreEqual(transform.TranslateY, 20); Assert.AreEqual(transform.ScaleX, 1.2, 0.0000001); Assert.AreEqual(transform.ScaleY, 1, 0.0000001); Assert.AreEqual(button.Opacity, 0.7, 0.0000001); }); }
private void ContainerItem_Loaded(object sender, RoutedEventArgs e) { var itemsPanel = (ItemsWrapGrid)SamplePickerGridView.ItemsPanelRoot; var itemContainer = (GridViewItem)sender; itemContainer.Loaded -= this.ContainerItem_Loaded; var button = itemContainer.FindDescendant <Button>(); if (button != null) { button.Click -= MoreInfoClicked; button.LostFocus -= MoreInfoLostFocus; button.Click += MoreInfoClicked; button.LostFocus += MoreInfoLostFocus; } var itemIndex = SamplePickerGridView.IndexFromContainer(itemContainer); var referenceIndex = itemsPanel.FirstVisibleIndex; if (SamplePickerGridView.SelectedIndex >= 0) { referenceIndex = SamplePickerGridView.SelectedIndex; } var relativeIndex = Math.Abs(itemIndex - referenceIndex); if (itemContainer.Content != CurrentSample && itemIndex >= 0 && itemIndex >= itemsPanel.FirstVisibleIndex && itemIndex <= itemsPanel.LastVisibleIndex) { var staggerDelay = TimeSpan.FromMilliseconds(relativeIndex * 30); VisualExtensions.SetNormalizedCenterPoint(itemContainer, "0.5"); AnimationBuilder.Create() .Opacity(from: 0, to: 1, delay: staggerDelay) .Scale(from: 0.9, to: 1, delay: staggerDelay) .Start(itemContainer); } }
private void Show() { if (this.AssociatedObject == null) { return; } StopAnimation(); if (IsAnimationEnabled) { var ct = CreateAnimationCancellationToken(); _ = AnimationBuilder.Create().Opacity(1.0).StartAsync(this.AssociatedObject, ct); if (IsAutoHideEnabled) { AutoHideSubject.OnNext(0); } } else { AssociatedObject.Opacity = 1.0; } }
public async Task ShowAsync() { Visibility = Visibility.Visible; await AnimationBuilder.Create().Translation(Axis.Y, 0, contentHeight, TimeSpan.FromMilliseconds(500), easingMode: EasingMode.EaseInOut).StartAsync(this); }
private async void ImageRotate_Click(object sender, RoutedEventArgs e) { PhotoDisplaySupport Item = PhotoCollection[Flip.SelectedIndex]; if (Flip.ContainerFromItem(Item) is DependencyObject Container && Container.FindChildOfType <ScrollViewer>() is ScrollViewer Viewer) { switch (Item.RotateAngle % 360) { case 0: case 180: { DoubleAnimation WidthAnimation = new DoubleAnimation { From = Flip.ActualWidth, To = Flip.ActualHeight, Duration = TimeSpan.FromMilliseconds(500), EnableDependentAnimation = true, EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(WidthAnimation, Viewer); Storyboard.SetTargetProperty(WidthAnimation, "Width"); Vector2 StartRotationCenter = new Vector2(Convert.ToSingle(Flip.ActualWidth / 2), Convert.ToSingle(Flip.ActualHeight / 2)); Vector2 EndRotationCenter = new Vector2(Convert.ToSingle(Flip.ActualHeight / 2), Convert.ToSingle(Flip.ActualHeight / 2)); await AnimationBuilder.Create() .CenterPoint(EndRotationCenter, StartRotationCenter, duration: TimeSpan.FromMilliseconds(500), easingType: EasingType.Cubic, easingMode: EasingMode.EaseOut) .ExternalAnimation(WidthAnimation) .RotationInDegrees(Item.RotateAngle += 90, duration: TimeSpan.FromMilliseconds(500), easingType: EasingType.Cubic, easingMode: EasingMode.EaseOut) .StartAsync(Viewer); break; } case 90: case 270: { DoubleAnimation HeightAnimation = new DoubleAnimation { From = Flip.ActualHeight, To = Flip.ActualWidth, Duration = TimeSpan.FromMilliseconds(500), EnableDependentAnimation = true, EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(HeightAnimation, Viewer); Storyboard.SetTargetProperty(HeightAnimation, "Width"); Vector2 StartRotationCenter = new Vector2(Convert.ToSingle(Flip.ActualHeight / 2), Convert.ToSingle(Flip.ActualHeight / 2)); Vector2 EndRotationCenter = new Vector2(Convert.ToSingle(Flip.ActualWidth / 2), Convert.ToSingle(Flip.ActualHeight / 2)); await AnimationBuilder.Create() .CenterPoint(EndRotationCenter, StartRotationCenter, duration: TimeSpan.FromMilliseconds(500), easingType: EasingType.Cubic, easingMode: EasingMode.EaseOut) .ExternalAnimation(HeightAnimation) .RotationInDegrees(Item.RotateAngle += 90, duration: TimeSpan.FromMilliseconds(500), easingType: EasingType.Cubic, easingMode: EasingMode.EaseOut) .StartAsync(Viewer); break; } } } }