private void ConfigureInteractionTracker() { _tracker = InteractionTracker.Create(_compositor); _interactionSource = VisualInteractionSource.Create(_root); _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly; _tracker.InteractionSources.Add(_interactionSource); _tracker.MaxPosition = new Vector3(0, (float)Root.ActualHeight, 0); // // Use the Tacker's Position (negated) to apply to the Offset of the Image. // var positionExpression = _compositor.CreateExpressionAnimation("-tracker.Position"); positionExpression.SetReferenceParameter("tracker", _tracker); _image.StartAnimation("Offset", positionExpression); }
public SwipeDismissPanel() { m_rootVisual = ElementCompositionPreview.GetElementVisual(this); m_compositor = m_rootVisual.Compositor; CompletedOffset = 2000; CompletionThreshold = 400; m_interactionSource = VisualInteractionSource.Create(m_rootVisual); m_interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; var snapHomeEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor); snapHomeEndpoint.Condition = m_compositor.CreateExpressionAnimation("true"); snapHomeEndpoint.RestingValue = m_compositor.CreateExpressionAnimation("0"); var snapNearConditionExpression = m_compositor.CreateExpressionAnimation( "target.Position.X < -target.CompletionThreshold"); var snapNearValueExpression = m_compositor.CreateExpressionAnimation("-target.CompletedOffset"); var snapNearEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor); snapNearEndpoint.Condition = snapNearConditionExpression; snapNearEndpoint.RestingValue = snapNearValueExpression; var snapFarConditionExpression = m_compositor.CreateExpressionAnimation( "target.Position.X > target.CompletionThreshold"); var snapFarValueExpression = m_compositor.CreateExpressionAnimation("target.CompletedOffset"); var snapFarEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor); snapFarEndpoint.Condition = snapFarConditionExpression; snapFarEndpoint.RestingValue = snapFarValueExpression; m_inertiaModifiers = new InteractionTrackerInertiaModifier[] { snapNearEndpoint, snapFarEndpoint, snapHomeEndpoint }; this.Loading += OnLoading; this.Unloaded += OnUnloaded; }
private void ConfigureInteractionTracker() { _interactionSource = VisualInteractionSource.Create(_hitTest); //Configure for y-direction panning _interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly; _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.PositionXChainingMode = InteractionChainingMode.Never; _interactionSource.IsPositionXRailsEnabled = true; //Create tracker and associate interaction source _tracker = InteractionTracker.CreateWithOwner(_visual.Compositor, this); _tracker.InteractionSources.Add(_interactionSource); _tracker.MaxPosition = new Vector3(_reply ? 72 : 0); _tracker.MinPosition = new Vector3(_forward ? -72 : 0); _tracker.Properties.InsertBoolean("CanReply", _reply); _tracker.Properties.InsertBoolean("CanForward", _forward); ConfigureAnimations(_visual, null); ConfigureRestingPoints(); }
private void SetupTracker() { _tracker = InteractionTracker.CreateWithOwner(compositor, this); InitTrackerPositions(); _source = VisualInteractionSource.Create(ReaderViewVisual); _source.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly; _source.IsPositionXRailsEnabled = false; _source.PositionXChainingMode = InteractionChainingMode.Never; _source.PositionXSourceMode = InteractionSourceMode.EnabledWithoutInertia; _source.IsPositionYRailsEnabled = false; _source.PositionYChainingMode = InteractionChainingMode.Never; _source.PositionYSourceMode = InteractionSourceMode.Disabled; _tracker.InteractionSources.Add(_source); OffsetBind = compositor.CreateExpressionAnimation("-tracker.Position"); OffsetBind.SetReferenceParameter("tracker", _tracker); PanelVisual.StartAnimation("Offset", OffsetBind); }
private void InitializeComposition() { this.compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; this.thumbVisual = ElementCompositionPreview.GetElementVisual(thumb); this.trackVisual = ElementCompositionPreview.GetElementVisual(trackCanvas); propSet = this.compositor.CreatePropertySet(); trackCanvas.PointerWheelChanged += new PointerEventHandler(PointerWheel_Changed); trackCanvas.PointerMoved += new PointerEventHandler(MousePointer_Moved); trackCanvas.PointerReleased += new PointerEventHandler(MousePointer_Released); // These pointer events are needed if want to click-to-seek. Weird eventing issues between when these get called and when need to call OnDragStart() and OnDragStop() methods // trackCanvas.PointerPressed += new PointerEventHandler(MousePointer_Pressed); // thumb.PointerPressed += new PointerEventHandler(MousePointer_ThumbPressed); this.interactionSource = VisualInteractionSource.Create(this.trackVisual); this.interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; this.tracker = InteractionTracker.CreateWithOwner(this.compositor, this); this.tracker.InteractionSources.Add(this.interactionSource); // This is the Expression that we will use to drive the position of the Thumb Scrubber // Idea is that we will then update the position of InteractionTracker to move thes scrubber around - this is done via the Pointer Events tied to the TrackCanvas object // Note: this is using ExpressionBuilder this.thumbExpressionAnimation = -tracker.GetReference().Position.X; }
public void ConfigureInteraction() { this.interactionSource = VisualInteractionSource.Create(myDrawingVisual); this.interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; this.interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; this.interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithInertia; this.tracker = InteractionTracker.CreateWithOwner(this.compositor, this); this.tracker.InteractionSources.Add(this.interactionSource); this.moveSurfaceExpressionAnimation = this.compositor.CreateExpressionAnimation("-tracker.Position.X"); this.moveSurfaceExpressionAnimation.SetReferenceParameter("tracker", this.tracker); this.scaleSurfaceUpDownExpressionAnimation = this.compositor.CreateExpressionAnimation("tracker.Scale"); this.scaleSurfaceUpDownExpressionAnimation.SetReferenceParameter("tracker", this.tracker); this.moveSurfaceUpDownExpressionAnimation = this.compositor.CreateExpressionAnimation("-tracker.Position.Y"); this.moveSurfaceUpDownExpressionAnimation.SetReferenceParameter("tracker", this.tracker); this.tracker.MinPosition = new System.Numerics.Vector3(0, 0, 0); //TODO: use same consts as tilemanager object this.tracker.MinScale = 0.01f; this.tracker.MaxScale = 100.0f; }
private void ConfigureInteractionTracker() { _interactionSource = VisualInteractionSource.Create(_rootContainer); _interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; _tracker = InteractionTracker.CreateWithOwner(_compositor, this); _tracker.MinScale = 0.6f; _tracker.MaxScale = 5.0f; _tracker.MaxPosition = new Vector3((float)Root.ActualWidth * 1.5f, 0, 0); _tracker.MinPosition = _tracker.MaxPosition * -1; _tracker.ScaleInertiaDecayRate = 0.96f; _tracker.InteractionSources.Add(_interactionSource); var tracker = _tracker.GetReference(); // // Here's the trick: we take the scale output from the tracker, and convert it into a // value that represents Z. Then we bind it to the world container's Z position. // var scaleExpression = EF.Lerp(0, 1000, (1 - tracker.Scale) / (1 - tracker.MaxScale)); _worldContainer.StartAnimation("Offset.Z", scaleExpression); // // Bind the output of the tracker to the world container's XY position. // _worldContainer.StartAnimation("Offset.XY", -tracker.Position.XY); // // Scaling usually affects position. This depends on the center point of the scale. // But for our UI, we want don't scale to adjust the position (since we're using scale // to change Offset.Z). So to prevent scale from affecting position, we must always use // the top-left corner of the WorldContainer as the center point (note: we could also // use the tracker's negated position, since that's where WorldContainer is getting its // offset). // // Create input modifiers to override the center point value. // var centerpointXModifier = CompositionConditionalValue.Create(_compositor); var centerpointYModifier = CompositionConditionalValue.Create(_compositor); centerpointXModifier.Condition = _compositor.CreateExpressionAnimation("true"); centerpointXModifier.Value = _compositor.CreateExpressionAnimation("world.Offset.X"); centerpointXModifier.Value.SetReferenceParameter("world", _worldContainer); _interactionSource.ConfigureCenterPointXModifiers(new[] { centerpointXModifier }); _tracker.ConfigureCenterPointXInertiaModifiers(new[] { centerpointXModifier }); centerpointYModifier.Condition = _compositor.CreateExpressionAnimation("true"); centerpointYModifier.Value = _compositor.CreateExpressionAnimation("world.Offset.Y"); centerpointYModifier.Value.SetReferenceParameter("world", _worldContainer); _interactionSource.ConfigureCenterPointYModifiers(new[] { centerpointYModifier }); _tracker.ConfigureCenterPointYInertiaModifiers(new[] { centerpointYModifier }); }
private void ConfigureInteractionTracker() { if (InfoContent == null) { return; } if (HittestContent == null) { return; } // Configure hittestVisual size for the interaction (size needs to be explicitly set in order for the hittesting to work correctly due to XAML-COMP interop policy) _hittestVisual.Size = new Vector2((float)HittestContent.ActualWidth, (float)HittestContent.ActualHeight); _props = _compositor.CreatePropertySet(); Visual infoVisual = ElementCompositionPreview.GetElementVisual(InfoContent); Visual photoVisual = ElementCompositionPreview.GetElementVisual(PhotoContent); photoVisual.Size = new Vector2((float)PhotoContent.ActualWidth, (float)PhotoContent.ActualHeight); photoVisual.CenterPoint = new Vector3((float)PhotoContent.ActualWidth * .5f, (float)PhotoContent.ActualHeight * .5f, 0f); infoVisual.CenterPoint = new Vector3((float)InfoContent.ActualWidth * .5f, (float)InfoContent.ActualHeight * .5f, 0f); VisualInteractionSource interactionSource = VisualInteractionSource.Create(_hittestVisual); //Configure for y-direction panning interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; //Create tracker and associate interaction source _tracker.InteractionSources.Add(interactionSource); //Configure tracker boundaries _tracker.MaxPosition = new Vector3((float)HittestContent.ActualHeight); SpriteVisual shadowVisual = _compositor.CreateSpriteVisual(); shadowVisual.Size = photoVisual.Size; ElementCompositionPreview.SetElementChildVisual(InfoContainer, shadowVisual); ConfigureAnimations(photoVisual, infoVisual, shadowVisual); ConfigureRestingPoints(); HittestContent.PointerPressed += (s, a) => { // Capture the touch manipulation to the InteractionTracker for automatic handling if (a.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) { try { interactionSource.TryRedirectForManipulation(a.GetCurrentPoint(s as UIElement)); } catch (UnauthorizedAccessException) { // Ignoring the failed redirect to prevent app crashing } } // Update the InteractionTracker's position to change between min and max for other input types else { float direction = 1; if (_isExpanded) { direction = -1; } _tracker.TryUpdatePositionWithAdditionalVelocity(new Vector3(0f, direction * 1000f, 0f)); } }; }
public SwipeDismissPanel() { m_rootVisual = ElementCompositionPreview.GetElementVisual(this); m_compositor = m_rootVisual.Compositor; CompletedOffset = 2000; CompletionThreshold = 400; #if SDKVERSION_RS1 m_interactionSource = VisualInteractionSource.Create(m_rootVisual); m_interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; var snapHomeEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor); snapHomeEndpoint.Condition = m_compositor.CreateExpressionAnimation("true"); snapHomeEndpoint.RestingValue = m_compositor.CreateExpressionAnimation("0"); var snapNearConditionExpression = m_compositor.CreateExpressionAnimation( "target.Position.X < -target.CompletionThreshold"); var snapNearValueExpression = m_compositor.CreateExpressionAnimation("-target.CompletedOffset"); var snapNearEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor); snapNearEndpoint.Condition = snapNearConditionExpression; snapNearEndpoint.RestingValue = snapNearValueExpression; var snapFarConditionExpression = m_compositor.CreateExpressionAnimation( "target.Position.X > target.CompletionThreshold"); var snapFarValueExpression = m_compositor.CreateExpressionAnimation("target.CompletedOffset"); var snapFarEndpoint = InteractionTrackerInertiaRestingValue.Create(m_compositor); snapFarEndpoint.Condition = snapFarConditionExpression; snapFarEndpoint.RestingValue = snapFarValueExpression; #else m_interactionSource = new VisualInteractionSource(m_compositor, m_rootVisual); m_interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; var snapHomeEndpoint = m_compositor.CreateInteractionTrackerInertiaEndpoint(); snapHomeEndpoint.Condition = m_compositor.CreateExpressionAnimation("true"); snapHomeEndpoint.Endpoint = m_compositor.CreateExpressionAnimation("0"); var snapNearConditionExpression = m_compositor.CreateExpressionAnimation( "target.ScrollPosition.X < -target.CompletionThreshold"); var snapNearValueExpression = m_compositor.CreateExpressionAnimation("-target.CompletedOffset"); var snapNearEndpoint = m_compositor.CreateInteractionTrackerInertiaEndpoint(); snapNearEndpoint.Condition = snapNearConditionExpression; snapNearEndpoint.Endpoint = snapNearValueExpression; var snapFarConditionExpression = m_compositor.CreateExpressionAnimation( "target.ScrollPosition.X > target.CompletionThreshold"); var snapFarValueExpression = m_compositor.CreateExpressionAnimation("target.CompletedOffset"); var snapFarEndpoint = m_compositor.CreateInteractionTrackerInertiaEndpoint(); snapFarEndpoint.Condition = snapFarConditionExpression; snapFarEndpoint.Endpoint = snapFarValueExpression; #endif m_inertiaModifiers = new InteractionTrackerInertiaModifier[] { snapNearEndpoint, snapFarEndpoint, snapHomeEndpoint }; this.Loading += OnLoading; this.Unloaded += OnUnloaded; }
/// <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 }); }
private void MainPage_Loaded(object sender, RoutedEventArgs e) { ThumbnailList.ItemsSource = new List <Item> { new Item { Name = "Daren" }, new Item { Name = "Kendra" }, new Item { Name = "Gavin" }, new Item { Name = "Naia" }, new Item { Name = "Frodo" }, new Item { Name = "Stella" }, new Item { Name = "DJ" }, new Item { Name = "Stasch" } }; // InteractionTracker and VisualInteractionSource setup. _root = ElementCompositionPreview.GetElementVisual(Root); _contentPanelVisual = ElementCompositionPreview.GetElementVisual(ContentPanel); _compositor = _root.Compositor; _tracker = InteractionTracker.Create(_compositor); _interactionSource = VisualInteractionSource.Create(_root); _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.PositionYChainingMode = InteractionChainingMode.Always; _tracker.InteractionSources.Add(_interactionSource); var refreshPanelHeight = (float)RefreshPanel.ActualHeight; _tracker.MaxPosition = new Vector3((float)Root.ActualWidth, 0, 0); _tracker.MinPosition = new Vector3(-(float)Root.ActualWidth, -refreshPanelHeight, 0); // Use the Tacker's Position (negated) to apply to the Offset of the Image. // The -{refreshPanelHeight} is to hide the refresh panel m_positionExpression = _compositor.CreateExpressionAnimation($"-tracker.Position.Y - {refreshPanelHeight} "); m_positionExpression.SetReferenceParameter("tracker", _tracker); _contentPanelVisual.StartAnimation("Offset.Y", m_positionExpression); var resistanceModifier = CompositionConditionalValue.Create(_compositor); var resistanceCondition = _compositor.CreateExpressionAnimation( $"-tracker.Position.Y < {pullToRefreshDistance}"); resistanceCondition.SetReferenceParameter("tracker", _tracker); var resistanceAlternateValue = _compositor.CreateExpressionAnimation( "source.DeltaPosition.Y / 3"); resistanceAlternateValue.SetReferenceParameter("source", _interactionSource); resistanceModifier.Condition = resistanceCondition; resistanceModifier.Value = resistanceAlternateValue; var stoppingModifier = CompositionConditionalValue.Create(_compositor); var stoppingCondition = _compositor.CreateExpressionAnimation( $"-tracker.Position.Y >= {pullToRefreshDistance}"); stoppingCondition.SetReferenceParameter("tracker", _tracker); var stoppingAlternateValue = _compositor.CreateExpressionAnimation("0"); stoppingModifier.Condition = stoppingCondition; stoppingModifier.Value = stoppingAlternateValue; //Now add the 2 source modifiers to the InteractionTracker. var modifierList = new List <CompositionConditionalValue> { resistanceModifier, stoppingModifier }; _interactionSource.ConfigureDeltaPositionYModifiers(modifierList); //The PointerPressed handler needs to be added using AddHandler method with the //handledEventsToo boolean set to "true" //instead of the XAML element's "PointerPressed=Window_PointerPressed", //because the list view needs to chain PointerPressed handled events as well. ContentPanel.AddHandler(PointerPressedEvent, new PointerEventHandler(Window_PointerPressed), true); }
private void SetupInteraction() { if (DesignMode.DesignModeEnabled) { return; } if (Compositor == null) { return; } if (ContentBorderVisual == null) { return; } m_tracker = InteractionTracker.CreateWithOwner(Compositor, this); var height = (float)ContentBorder.ActualHeight; m_tracker.MaxPosition = new Vector3(0f, 0f, 0f); m_tracker.MinPosition = new Vector3(0f, -height, 0f); m_source = VisualInteractionSource.Create(ContentBorderVisual); m_source.IsPositionYRailsEnabled = true; m_source.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly; m_source.PositionYChainingMode = InteractionChainingMode.Auto; m_source.PositionYSourceMode = InteractionSourceMode.EnabledWithoutInertia; m_tracker.InteractionSources.Add(m_source); m_open = InteractionTrackerInertiaRestingValue.Create(Compositor); m_open.Condition = Compositor.CreateExpressionAnimation("this.Target.NaturalRestingPosition.Y > -host.Size.Y / 3"); m_open.RestingValue = Compositor.CreateExpressionAnimation("0"); m_open.Condition.SetReferenceParameter("host", ContentBorderVisual); m_open.RestingValue.SetReferenceParameter("host", ContentBorderVisual); m_close = InteractionTrackerInertiaRestingValue.Create(Compositor); m_close.Condition = Compositor.CreateExpressionAnimation("this.Target.NaturalRestingPosition.Y <= -host.Size.Y / 3"); m_close.RestingValue = Compositor.CreateExpressionAnimation("-host.Size.Y"); m_close.Condition.SetReferenceParameter("host", ContentBorderVisual); m_close.RestingValue.SetReferenceParameter("host", ContentBorderVisual); //Release模式会爆炸 //var modifiers = new InteractionTrackerInertiaRestingValue[] { m_open, m_close }; //m_tracker.ConfigurePositionYInertiaModifiers(modifiers); ContentOffsetExp = Compositor.CreateExpressionAnimation("Max(-15f, -tracker.Position.Y)"); ContentOffsetExp.SetReferenceParameter("tracker", m_tracker); ContentBorderVisual.StartAnimation("Translation.Y", ContentOffsetExp); LightDismissLayerOpacityExp = Compositor.CreateExpressionAnimation("Clamp(1 + (tracker.Position.Y / host.Size.Y),0,1)"); LightDismissLayerOpacityExp.SetReferenceParameter("tracker", m_tracker); LightDismissLayerOpacityExp.SetReferenceParameter("host", ContentBorderVisual); LightDismissLayerVisual.StartAnimation("Opacity", LightDismissLayerOpacityExp); OpenAnimation = Compositor.CreateVector3KeyFrameAnimation(); OpenAnimation.InsertExpressionKeyFrame(0f, "Vector3(0f, -host.Size.Y, 0f)"); OpenAnimation.InsertKeyFrame(1f, new Vector3(0f, 15f, 0f)); OpenAnimation.SetReferenceParameter("host", ContentBorderVisual); OpenAnimation.Duration = TimeSpan.FromSeconds(0.3d); ToOpenAnimation = Compositor.CreateVector3KeyFrameAnimation(); ToOpenAnimation.InsertKeyFrame(1f, new Vector3(0f, 5f, 0f)); ToOpenAnimation.SetReferenceParameter("host", ContentBorderVisual); ToOpenAnimation.Duration = TimeSpan.FromSeconds(0.3d); CloseAnimation = Compositor.CreateVector3KeyFrameAnimation(); CloseAnimation.InsertExpressionKeyFrame(1f, "Vector3(0f, -host.Size.Y, 0f)"); CloseAnimation.SetReferenceParameter("host", ContentBorderVisual); CloseAnimation.Duration = TimeSpan.FromSeconds(0.3d); }