private void MainGrid_SizeChanged(object sender, SizeChangedEventArgs e) { if (_scenarios.Count > 0) { // Resize the container for each scenario ContainerVisual previousScenarioContainer = null; for (int i = 0; i < _scenarios.Count; i++) { var scenarioContainer = _scenarioContainersMapping[_scenarios[i]]; scenarioContainer.Size = new Vector2((float)MainCanvas.ActualWidth, (float)MainCanvas.ActualHeight); // Update offset when applicable if (previousScenarioContainer != null) { scenarioContainer.Offset = new Vector3(previousScenarioContainer.Offset.X + previousScenarioContainer.Size.X, 0, 0); } // Update content on a per-scenario basis _scenarios[i].SizeChanged(); previousScenarioContainer = scenarioContainer; } // Update tracker position var newOffset = _scenarioContainersMapping[_currentScenario].Offset; _tracker.TryUpdatePosition(newOffset); // Update resting points var backgroundVisual = ElementCompositionPreview.GetElementVisual(MainGrid); backgroundVisual.Size = new Vector2((float)MainGrid.ActualWidth, (float)MainGrid.ActualHeight); _tracker.MaxPosition = new Vector3((float)backgroundVisual.Size.X * _scenarios.Count, backgroundVisual.Size.Y, 0); ConfigureRestingPoints(); } }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); LayoutRoot = (Grid)GetTemplateChild("LayoutRoot"); ITRoot = (Grid)GetTemplateChild("ITRoot"); Layer = (Border)GetTemplateChild("Layer"); ModalContent = (StackPanel)GetTemplateChild("ModalContent"); TitleBar = (Grid)GetTemplateChild("TitleBar"); CloseButton = (Button)GetTemplateChild("CloseButton"); DebugText1 = (TextBlock)GetTemplateChild("DebugText1"); DebugText2 = (TextBlock)GetTemplateChild("DebugText2"); DebugText3 = (TextBlock)GetTemplateChild("DebugText3"); Resize(); Window.Current.SizeChanged += (a, b) => { Resize(b.Size); }; Loaded += (a, b) => { Resize(); // resize popup and layoutroot SetupModal(); _tracker.TryUpdatePosition(new Vector3(0, _tracker.MinPosition.Y + 1, 0)); OpenHalf(); }; ITRoot.PointerPressed += (a, b) => { try { _is.TryRedirectForManipulation(b.GetCurrentPoint(this)); } catch (Exception ex) { Debug.WriteLine("TryRedirectForManipulation: " + ex.ToString()); } }; ITRoot.PointerWheelChanged += (a, b) => { var o = b.GetCurrentPoint(a as UIElement); int z = o.Properties.MouseWheelDelta; float d = (float)z * 1.5f; DebugText3.Text = $"Wheel: {z}\nDelta: {d}"; if (d != 0 && _tracker.Position.Y >= _tracker.MinPosition.Y + StartHeight && _tracker.Position.Y <= _tracker.MaxPosition.Y) { if (_tracker.Position.Y == _tracker.MaxPosition.Y && d < 0) { return; } _tracker.TryUpdatePositionWithAnimation(GetScrollKFA(new Vector3(0, _tracker.Position.Y - d, 0))); } }; CloseButton.Click += (a, b) => { Hide(); }; WasShowed = true; }
private void GotoIndex(int index, bool UseAnimation = true) { if (index < 0) { return; } if (UseAnimation) { OffsetAnimation.InsertKeyFrame(1f, new Vector3((float)(this.ActualWidth * index), 0f, 0f)); m_tracker.TryUpdatePositionWithAnimation(OffsetAnimation); //PanelVisual.StartAnimation("Offset", OffsetAnimation); } else { m_tracker.TryUpdatePosition(new Vector3((float)(this.ActualWidth * index), 0f, 0f)); //PanelVisual.Offset = new Vector3((float)(-this.ActualWidth * index), 0f, 0f); } }
private async Task ResetMediaCopyAsync() { CardsHost.IsHitTestVisible = false; // Reset the opacity, scale and position of the "copy" and fade in the real video player. await MediaCopy .Offset(offsetY : 0.0f, duration : 300d) .Scale(1.0f, 1.0f, (float)Card.ActualWidth / 2, (float)Card.ActualHeight / 2, 300d) .StartAsync(); MediaCopy.Fade(0.0f, 400d).Start(); await Card.Fade(1.0f, 400d).StartAsync(); // Reset the InteractionTracker's position. _tracker.TryUpdatePosition(Vector3.Zero); CardsHost.IsHitTestVisible = true; MediaContainer.IsHitTestVisible = true; }
private void changeViewTo(bool hideGdInfo, bool disableAnimation) { if (isGdInfoHide == hideGdInfo && !disableAnimation) { return; } if (tracker is null) { return; } isGdInfoHideDef = hideGdInfo; if (disableAnimation) { tracker.TryUpdatePosition(hideGdInfo ? tracker.MaxPosition : tracker.MinPosition); } else { var ani = compositor.CreateVector3KeyFrameAnimation(); ani.InsertKeyFrame(1, hideGdInfo ? tracker.MaxPosition : tracker.MinPosition); tracker.TryUpdatePositionWithAnimation(ani); } }
public void PrepareForItemOverride(MessageViewModel message) { _reply = CanReply(); _forward = CanForward(); if (_tracker != null) { _tracker.Properties.InsertBoolean("CanReply", _reply); _tracker.Properties.InsertBoolean("CanForward", _forward); _tracker.MaxPosition = new Vector3(_reply ? 72 : 0); _tracker.MinPosition = new Vector3(_forward ? -72 : 0); if (_tracker.Position.X != 0) { _tracker.TryUpdatePosition(new Vector3()); } if (_visual != null && _visual.Offset.X != 0) { _visual.Offset = new Vector3(); } } }
/// <summary> /// Setup interactions with sliding touch controls. /// </summary> /// <param name="detachedHeader">Uneffected element.</param> public void SetupInteraction(UIElement detachedHeader = null) { // Set up tracker var containerVisual = _compositor.CreateContainerVisual(); contentVis = ElementCompositionPreview.GetElementVisual(content); if (detachedHeader != null) { contentVis2 = ElementCompositionPreview.GetElementVisual(detachedHeader); } ElementCompositionPreview.SetIsTranslationEnabled(content, true); if (detachedHeader != null) { ElementCompositionPreview.SetIsTranslationEnabled(detachedHeader, true); } contentVis.Properties.InsertVector3("Translation", Vector3.Zero); if (detachedHeader != null) { contentVis2.Properties.InsertVector3("Translation", Vector3.Zero); } _interactionSource = VisualInteractionSource.Create(_rootVisual); _interactionSource.IsPositionXRailsEnabled = true; // If the chaining mode is set to always, it is impossible to go past by the minimum and maximum scrolling points by "stretching" the X axis _interactionSource.PositionXChainingMode = InteractionChainingMode.Always; _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; _tracker = InteractionTracker.Create(_compositor); _tracker.MaxPosition = new Vector3(width - 72, 0, 0); _tracker.MinPosition = new Vector3(-width, 0, 0); _tracker.TryUpdatePosition(new Vector3(0, 0, 0)); _tracker.InteractionSources.Add(_interactionSource); // Define expression animations _contentAnimation = _compositor.CreateExpressionAnimation("-tracker.Position.X"); _contentAnimation.SetReferenceParameter("tracker", _tracker); contentVis.StartAnimation("Translation.X", _contentAnimation); if (detachedHeader != null) { contentVis2.StartAnimation("Translation.X", _contentAnimation); } // LEFT PANEL leftcache1 = ElementCompositionPreview.GetElementVisual(leftPanelCache); leftpanel1 = ElementCompositionPreview.GetElementVisual(leftPanel); ElementCompositionPreview.SetIsTranslationEnabled(leftPanel, true); _leftPanelFadeAnimation = _compositor.CreateExpressionAnimation("Clamp((-tracker.Position.X/width)*(-0.5)+0.25,0,1)"); _leftPanelFadeAnimation.SetScalarParameter("width", width); _leftPanelFadeAnimation.SetReferenceParameter("tracker", _tracker); leftcache1.StartAnimation("Opacity", _leftPanelFadeAnimation); leftPanelTranslateAnimation = _compositor.CreateExpressionAnimation("-24+((-tracker.Position.X/width)*24)"); leftPanelTranslateAnimation.SetReferenceParameter("tracker", _tracker); leftPanelTranslateAnimation.SetScalarParameter("width", width); leftpanel1.StartAnimation("Translation.X", leftPanelTranslateAnimation); // SECONDARY LEFT PANEL leftcache2 = ElementCompositionPreview.GetElementVisual(leftSecondaryPanelCache); leftpanel2 = ElementCompositionPreview.GetElementVisual(leftSecondaryPanel); ElementCompositionPreview.SetIsTranslationEnabled(leftSecondaryPanel, true); _leftPanelFadeAnimation2 = _compositor.CreateExpressionAnimation("Clamp((-tracker.Position.X/width)*(-0.25)+0.25, 0, 1)"); _leftPanelFadeAnimation2.SetScalarParameter("width", width); _leftPanelFadeAnimation2.SetReferenceParameter("tracker", _tracker); leftcache2.StartAnimation("Opacity", _leftPanelFadeAnimation2); _leftPanelTranslateAnimation2 = _compositor.CreateExpressionAnimation("-tracker.Position.X/width*72"); _leftPanelTranslateAnimation2.SetReferenceParameter("tracker", _tracker); _leftPanelTranslateAnimation2.SetScalarParameter("width", width); leftpanel2.StartAnimation("Translation.X", _leftPanelTranslateAnimation2); // RIGHT PANEL rightcache = ElementCompositionPreview.GetElementVisual(rightPanelCache); rightpanel = ElementCompositionPreview.GetElementVisual(rightSide); ElementCompositionPreview.SetIsTranslationEnabled(rightSide, true); rightPanelFadeAnimation = _compositor.CreateExpressionAnimation("Clamp((tracker.Position.X/width)*(-0.25)+0.25, 0, 1)"); rightPanelFadeAnimation.SetScalarParameter("width", width - 72); rightPanelFadeAnimation.SetReferenceParameter("tracker", _tracker); rightcache.StartAnimation("Opacity", rightPanelFadeAnimation); rightPanelTranslateAnimation = _compositor.CreateExpressionAnimation("-tracker.Position.X/width*72"); rightPanelTranslateAnimation.SetReferenceParameter("tracker", _tracker); rightPanelTranslateAnimation.SetScalarParameter("width", width - 72); rightpanel.StartAnimation("Translation.X", rightPanelTranslateAnimation); SetSnapPoints(-width, 0, width - 72); // UI Stuff var state = VisualStateGroup.CurrentState; VisualStateGroup_CurrentStateChanged(null, new VisualStateChangedEventArgs() { OldState = Small }); }
public void SetupInteraction(UIElement DetachedHeader) { //Set up tracker var containerVisual = compositor.CreateContainerVisual(); contentVis = ElementCompositionPreview.GetElementVisual(content); contentVis2 = ElementCompositionPreview.GetElementVisual(DetachedHeader); ElementCompositionPreview.SetIsTranslationEnabled(content, true); ElementCompositionPreview.SetIsTranslationEnabled(DetachedHeader, true); contentVis.Properties.InsertVector3("Translation", Vector3.Zero); contentVis2.Properties.InsertVector3("Translation", Vector3.Zero); interactionSource = VisualInteractionSource.Create(rootVisual); interactionSource.IsPositionXRailsEnabled = true; //If the chaining mode is set to always, it is impossible to go past by the minimum and maximum scrolling points by "stretching" the X axis interactionSource.PositionXChainingMode = InteractionChainingMode.Always; interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; tracker = InteractionTracker.Create(compositor); tracker.MaxPosition = new Vector3(width - 72, 0, 0); tracker.MinPosition = new Vector3(-width, 0, 0); tracker.TryUpdatePosition(new Vector3(0, 0, 0)); tracker.InteractionSources.Add(interactionSource); // Define expression animations contentAnimation = compositor.CreateExpressionAnimation("-tracker.Position.X"); contentAnimation.SetReferenceParameter("tracker", tracker); contentVis.StartAnimation("Translation.X", contentAnimation); contentVis2.StartAnimation("Translation.X", contentAnimation); //LEFT PANEL leftcache1 = ElementCompositionPreview.GetElementVisual(leftPanelCache); leftpanel1 = ElementCompositionPreview.GetElementVisual(leftPanel); ElementCompositionPreview.SetIsTranslationEnabled(leftPanel, true); leftPanelFadeAnimation = compositor.CreateExpressionAnimation("Clamp((-tracker.Position.X/width)*(-0.5)+0.25,0,1)"); leftPanelFadeAnimation.SetScalarParameter("width", width); leftPanelFadeAnimation.SetReferenceParameter("tracker", tracker); leftcache1.StartAnimation("Opacity", leftPanelFadeAnimation); leftPanelTranslateAnimation = compositor.CreateExpressionAnimation("-24+((-tracker.Position.X/width)*24)"); leftPanelTranslateAnimation.SetReferenceParameter("tracker", tracker); leftPanelTranslateAnimation.SetScalarParameter("width", width); leftpanel1.StartAnimation("Translation.X", leftPanelTranslateAnimation); //SECONDARY LEFT PANEL leftcache2 = ElementCompositionPreview.GetElementVisual(leftSecondaryPanelCache); leftpanel2 = ElementCompositionPreview.GetElementVisual(leftSecondaryPanel); ElementCompositionPreview.SetIsTranslationEnabled(leftSecondaryPanel, true); leftPanelFadeAnimation2 = compositor.CreateExpressionAnimation("Clamp((-tracker.Position.X/width)*(-0.25)+0.25, 0, 1)"); leftPanelFadeAnimation2.SetScalarParameter("width", width); leftPanelFadeAnimation2.SetReferenceParameter("tracker", tracker); leftcache2.StartAnimation("Opacity", leftPanelFadeAnimation2); leftPanelTranslateAnimation2 = compositor.CreateExpressionAnimation("-tracker.Position.X/width*72"); leftPanelTranslateAnimation2.SetReferenceParameter("tracker", tracker); leftPanelTranslateAnimation2.SetScalarParameter("width", width); leftpanel2.StartAnimation("Translation.X", leftPanelTranslateAnimation2); //RIGHT PANEL rightcache = ElementCompositionPreview.GetElementVisual(rightPanelCache); rightpanel = ElementCompositionPreview.GetElementVisual(rightSide); ElementCompositionPreview.SetIsTranslationEnabled(rightSide, true); rightPanelFadeAnimation = compositor.CreateExpressionAnimation("Clamp((tracker.Position.X/width)*(-0.25)+0.25, 0, 1)"); rightPanelFadeAnimation.SetScalarParameter("width", width - 72); rightPanelFadeAnimation.SetReferenceParameter("tracker", tracker); rightcache.StartAnimation("Opacity", rightPanelFadeAnimation); rightPanelTranslateAnimation = compositor.CreateExpressionAnimation("-tracker.Position.X/width*72"); rightPanelTranslateAnimation.SetReferenceParameter("tracker", tracker); rightPanelTranslateAnimation.SetScalarParameter("width", width - 72); rightpanel.StartAnimation("Translation.X", rightPanelTranslateAnimation); SetSnapPoints(-width, 0, width - 72); //UI Stuff MediumTrigger.MinWindowWidth = Storage.Settings.RespUiM; LargeTrigger.MinWindowWidth = Storage.Settings.RespUiL; ExtraLargeTrigger.MinWindowWidth = Storage.Settings.RespUiXl; var state = VisualStateGroup.CurrentState; if (App.CinematicMode) { SmallTrigger.MinWindowWidth = 0; MediumTrigger.MinWindowWidth = 0; LargeTrigger.MinWindowWidth = 1; ExtraLargeTrigger.MinWindowWidth = 100000; maingrid.Margin = new Thickness(54, 0, 54, 0); leftPanel.Margin = new Thickness(-54, 0, 0, 0); leftPanel.Padding = new Thickness(54, 0, 0, 0); rightSide.Margin = new Thickness(0, 0, 54, 0); rightSide.Padding = new Thickness(0, 0, -54, 0); } VisualStateGroup_CurrentStateChanged(null, new VisualStateChangedEventArgs() { OldState = Small }); }