private void ConfigureInteractionTracker() { _tracker = InteractionTracker.Create(_compositor); _interactionSource = VisualInteractionSource.Create(_root); _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.PositionYChainingMode = InteractionChainingMode.Always; _tracker.InteractionSources.Add(_interactionSource); float refreshPanelHeight = (float)RefreshPanel.ActualHeight; _tracker.MaxPosition = new Vector3((float)Root.ActualWidth, 0, 0); _tracker.MinPosition = new Vector3(-(float)Root.ActualWidth, -refreshPanelHeight, 0); //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); SetupPullToRefreshBehavior(refreshPanelHeight); //Apply spring force to pull the content back to Zero ConfigureRestingPoint(refreshPanelHeight); // // Use the Tracker's Position (negated) to apply to the Offset of the Image. The -{refreshPanelHeight} is to hide the refresh panel // _contentPanelVisual.StartAnimation("Offset.Y", -_tracker.GetReference().Position.Y - refreshPanelHeight); }
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); }
private void page_Loaded(object sender, RoutedEventArgs e) { this.Loaded -= this.page_Loaded; this.spVisual = ElementCompositionPreview.GetElementVisual(this.spContent); this.btnScrollVisual = ElementCompositionPreview.GetElementVisual(this.btn_Scroll); this.compositor = this.spVisual.Compositor; this.tracker = InteractionTracker.Create(this.compositor); var tref = this.tracker.GetReference(); var trackerTarget = ExpressionValues.Target.CreateInteractionTrackerTarget(); var endpoint1 = InteractionTrackerInertiaRestingValue.Create(this.compositor); endpoint1.SetCondition(trackerTarget.NaturalRestingPosition.Y < (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2); endpoint1.SetRestingValue(trackerTarget.MinPosition.Y); var endpoint2 = InteractionTrackerInertiaRestingValue.Create(this.compositor); endpoint2.SetCondition(trackerTarget.NaturalRestingPosition.Y >= (trackerTarget.MaxPosition.Y - trackerTarget.MinPosition.Y) / 2); endpoint2.SetRestingValue(trackerTarget.MaxPosition.Y); this.tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { endpoint1, endpoint2 }); this.interactionSource = VisualInteractionSource.Create(this.spVisual); this.interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; this.tracker.InteractionSources.Add(this.interactionSource); this.propertySet = this.compositor.CreatePropertySet(); this.propertySet.InsertScalar("progress", 0.0f); this.propertySet.StartAnimation("progress", tref.Position.Y / tref.MaxPosition.Y); var progress = this.propertySet.GetReference().GetScalarProperty("progress"); this.btnScrollVisual.StartAnimation("RotationAngleInDegrees", ExpressionFunctions.Clamp(progress, 0f, 1f) * 180); this.btnScrollVisual.CenterPoint = new System.Numerics.Vector3((float)this.btn_Scroll.ActualWidth / 2, (float)this.btn_Scroll.ActualHeight / 2, 0); this.spVisual.StartAnimation("Offset.Y", -ExpressionFunctions.Clamp(progress, -0.4f, 1.4f) * tref.MaxPosition.Y); gdInfo_SizeChanged(this, null); }
private void ConfigSpringBasedTracker(UIElement element, double periodInMs, float dampingRatio, float finalValue = 0.0f, double delayInMs = 0.0f) { ElementCompositionPreview.SetIsTranslationEnabled(element, true); var tracker = InteractionTracker.Create(_compositor); tracker.InteractionSources.Add(_interactionSource); tracker.MaxPosition = new Vector3(Root.RenderSize.ToVector2(), 0.0f); tracker.MinPosition = -tracker.MaxPosition; var modifier = InteractionTrackerInertiaNaturalMotion.Create(_compositor); var springAnimation = _compositor.CreateSpringScalarAnimation(); springAnimation.Period = TimeSpan.FromMilliseconds(periodInMs); springAnimation.DampingRatio = dampingRatio; springAnimation.FinalValue = finalValue; // This will cause a black screen for a few seconds. Bug?? springAnimation.DelayTime = TimeSpan.FromMilliseconds(delayInMs); modifier.Condition = _compositor.CreateExpressionAnimation("true"); modifier.NaturalMotion = springAnimation; tracker.ConfigurePositionXInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); var imageVisual = ElementCompositionPreview.GetElementVisual(element); imageVisual.StartAnimation("Translation", -tracker.GetReference().Position); }
private async void AddInteractableImage() { // 將 containerVisual 與 spriteVisual 新增至 DemoPage6 中 var containerVisual = compositor.CreateContainerVisual(); var spriteVisual = compositor.CreateSpriteVisual(); containerVisual.Children.InsertAtTop(spriteVisual); ElementCompositionPreview.SetElementChildVisual(this, containerVisual); // 讀圖 var targetBrush = await GenerateCompositionBrush(); // 將圖片讀進 spriteVisual spriteVisual.Brush = targetBrush; spriteVisual.Size = new Vector2(300f, 300f); // 建立互動來源 (必須指定互動範圍區域) interactionSource = VisualInteractionSource.Create(rootVisual); // 設定互動方式 interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; // 建立 InteractionTracker tracker = InteractionTracker.Create(compositor); // 設定位移位置的最大值與最小值 // 類似 ScrollViewer.ScrollableHeight, ScrollViewer.ScrollableWidth tracker.MaxPosition = new Vector3(0, 300f, 0); tracker.MinPosition = new Vector3(); // 將互動來源加至 tracker tracker.InteractionSources.Add(interactionSource); // 用 tracker 來設定 animation const int topMargin = 100; var offsetYAnimation = compositor.CreateExpressionAnimation("-tracker.Position.Y + topMargin"); offsetYAnimation.SetReferenceParameter("tracker", tracker); offsetYAnimation.SetScalarParameter("topMargin", topMargin); spriteVisual.StartAnimation("Offset.Y", offsetYAnimation); //======================================================= // 讓 interactionSource 支援 Scale //tracker.MaxScale = 3.0f; //tracker.MinScale = 0.5f; //interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithoutInertia; //var scaleAnimation = compositor.CreateExpressionAnimation("tracker.Scale"); //scaleAnimation.SetReferenceParameter("tracker", tracker); //spriteVisual.StartAnimation("Scale.X", scaleAnimation); //spriteVisual.StartAnimation("Scale.Y", scaleAnimation); //var maxYAnimation = compositor.CreateExpressionAnimation("spriteVisual.Size.Y * spriteVisual.Scale.Y"); //maxYAnimation.SetReferenceParameter("spriteVisual", spriteVisual); //tracker.StartAnimation("MaxPosition.Y", maxYAnimation); }
private void SetupInput() { _root = ElementCompositionPreview.GetElementVisual(main); _compositor = _root.Compositor; _props = _compositor.CreatePropertySet(); _tracker = InteractionTracker.Create(_compositor); _tracker.MaxPosition = new Vector3((float)main.ActualHeight); _source = VisualInteractionSource.Create(_root); _source.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _tracker.InteractionSources.Add(_source); }
private void ConfigureInteractionTracker() { _tracker = InteractionTracker.Create(_compositor); _tracker.MaxPosition = new Vector3(0, _backgroundImageVisual.Size.Y * 0.5f, 0); _tracker.MinPosition = new Vector3(); _interactionSource = VisualInteractionSource.Create(_backgroundVisual); _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _tracker.InteractionSources.Add(_interactionSource); var trackerNode = _tracker.GetReference(); var progressExp = EF.Clamp(trackerNode.Position.Y / trackerNode.MaxPosition.Y, 0, 1); _propertySet.StartAnimation("progress", progressExp); }
private void ConfigureInteractionTracker() { _tracker = InteractionTracker.Create(_compositor); _interactionSource = VisualInteractionSource.Create(_root); _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _tracker.InteractionSources.Add(_interactionSource); _tracker.MaxPosition = new Vector3(0, (float)Root.ActualHeight, 0); SetDefaultInertia(); // // Use the Tacker's Position (negated) to apply to the Offset of the Image. // _image.StartAnimation("Offset", -_tracker.GetReference().Position); }
private void Interaction() { _interactionTracker = InteractionTracker.Create(_compositor); _interactionTracker.MinScale = 0; _interactionTracker.MaxScale = 100f; _interactionTracker.MaxPosition = new Vector3((float)Window.Current.Bounds.Width * 0.5f, (float)Window.Current.Bounds.Height * 0.5f, 0f); _interactionTracker.MinPosition = new Vector3(); _interactionSource = VisualInteractionSource.Create(ElementCompositionPreview.GetElementVisual(Window.Current.Content)); _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionTracker.InteractionSources.Add(_interactionSource); var blurEffect = new GaussianBlurEffect { BlurAmount = 0f, Optimization = EffectOptimization.Speed, Name = "blurEffect", Source = new CompositionEffectSourceParameter("image") }; var effectFactory = _compositor.CreateEffectFactory(blurEffect, new[] { "blurEffect.BlurAmount" }); var blurBrush = effectFactory.CreateBrush(); blurBrush.SetSourceParameter("image", _compositor.CreateBackdropBrush()); _sprite = _compositor.CreateSpriteVisual(); _sprite.Size = new Vector2((float)Window.Current.Bounds.Width, (float)Window.Current.Bounds.Height); _sprite.Brush = blurBrush; var blurAnimation = _compositor.CreateExpressionAnimation("lerp(tracker.MinScale, tracker.MaxScale, clamp(tracker.Position.X / width, 0, 1))"); blurAnimation.SetReferenceParameter("tracker", _interactionTracker); blurAnimation.SetScalarParameter("width", (float)Window.Current.Bounds.Width); _sprite.Brush.Properties.StartAnimation("blurEffect.BlurAmount", blurAnimation); ElementCompositionPreview.SetElementChildVisual(Image, _sprite); }
private void ConfigureInteractionTracker() { _tracker = InteractionTracker.Create(_compositor); _tracker.MaxPosition = new Vector3(0, _backgroundImageVisual.Size.Y * 0.5f, 0); _tracker.MinPosition = new Vector3(); _interactionSource = VisualInteractionSource.Create(_backgroundVisual); _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; #if SDKVERSION_17763 if (MainPage.RuntimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._17763)) { _interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadAndPointerWheel; } #endif _tracker.InteractionSources.Add(_interactionSource); var trackerNode = _tracker.GetReference(); var progressExp = EF.Clamp(trackerNode.Position.Y / trackerNode.MaxPosition.Y, 0, 1); _propertySet.StartAnimation("progress", progressExp); }
/// <summary> /// 当指针设备在窗口内按下时执行。此时我们来做交互。 /// </summary> private void InteractionTrackerSetup(Compositor compositor, Visual hitTestRoot) { // #1 Create InteractionTracker object var tracker = InteractionTracker.Create(compositor); // #2 Set Min and Max positions tracker.MinPosition = new Vector3(-1000f); tracker.MaxPosition = new Vector3(1000f); // #3 Setup the VisualInteractionSourc var source = VisualInteractionSource.Create(hitTestRoot); // #4 Set the properties for the VisualInteractionSource source.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly; source.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; source.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; // #5 Add the VisualInteractionSource to InteractionTracker tracker.InteractionSources.Add(source); }
/// <summary> /// Inializes a new instance of the <see cref="SideDrawer"/> class. /// </summary> public SideDrawer() { this.InitializeComponent(); Visual rootVisual = ElementCompositionPreview.GetElementVisual(rootgrid); _compositor = rootVisual.Compositor; // Main content _mainVisual = ElementCompositionPreview.GetElementVisual(main); ElementCompositionPreview.SetIsTranslationEnabled(main, true); // Main left panel _leftVisual = ElementCompositionPreview.GetElementVisual(left1); ElementCompositionPreview.SetIsTranslationEnabled(left1, true); // Secondary left panel _left2Visual = ElementCompositionPreview.GetElementVisual(left2); ElementCompositionPreview.SetIsTranslationEnabled(left2, true); // Right panel _rightVisual = ElementCompositionPreview.GetElementVisual(right); ElementCompositionPreview.SetIsTranslationEnabled(right, true); // Tracker _tracker = InteractionTracker.Create(_compositor); _interactionSource = VisualInteractionSource.Create(_mainVisual); _interactionSource.IsPositionXRailsEnabled = true; _interactionSource.PositionXChainingMode = InteractionChainingMode.Always; _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; // Inertia resting _startPoint = InteractionTrackerInertiaRestingValue.Create(_compositor); _midPoint = InteractionTrackerInertiaRestingValue.Create(_compositor); _endPoint = InteractionTrackerInertiaRestingValue.Create(_compositor); Loading += OnLoading; }
/// <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); }