/// <summary> /// Invoked whenever application code or internal processes (such as a rebuilding /// layout pass) call <see cref="OnApplyTemplate"/>. In simplest terms, this means the method /// is called just before a UI element displays in an application. Override this /// method to influence the default post-template logic of a class. /// </summary> protected override void OnApplyTemplate() { m_root = this.GetTemplateChild(PART_ROOT) as UIElement; m_scroller = this.GetTemplateChild(PART_SCROLLER) as ScrollViewer; m_scrollerContent = this.GetTemplateChild(PART_SCROLLER_CONTENT) as UIElement; m_refreshIndicatorContainer = this.GetTemplateChild(PART_REFRESH_INDICATOR) as FrameworkElement; m_defaultRefreshIndicatorTextBlock = this.GetTemplateChild(PART_DEFAULT_REFRESH_INDICATOR_CONTENT) as TextBlock; if (m_root != null && m_scroller != null && m_scrollerContent != null && m_refreshIndicatorContainer != null) { m_scroller.DirectManipulationStarted += Scroller_DirectManipulationStarted; m_scroller.DirectManipulationCompleted += Scroller_DirectManipulationCompleted; m_scroller.ViewChanged += Scroller_ViewChanged; m_scroller.AddHandler(UIElement.PointerPressedEvent, new PointerEventHandler(Scroller_PointerPressed), true); // In AutoRefresh mode, zoom factors smaller or larger than 1.0 are not supported. if (this.AutoRefresh) { m_scroller.MinZoomFactor = 1.0f; m_scroller.MaxZoomFactor = 1.0f; m_scroller.ZoomMode = ZoomMode.Disabled; } m_refreshIndicatorContainer.SizeChanged += RefreshIndicatorContainer_SizeChanged; } if (m_defaultRefreshIndicatorTextBlock != null) { m_defaultRefreshIndicatorTextBlock.Visibility = this.RefreshIndicatorContent == null ? Visibility.Visible : Visibility.Collapsed; } base.OnApplyTemplate(); }
/// <summary> /// Builds the visual tree for the <see cref="T:System.Windows.Controls.ListBox"/> /// control when a new template is applied. /// </summary> protected override void OnApplyTemplate() { base.OnApplyTemplate(); if (ElementScrollViewer != null) { // ElementScrollViewer.MouseMove -= viewer_MouseMove; ElementScrollViewer.DragEnter -= ElementScrollViewer_DragEnter; //ElementScrollViewer.ManipulationStarted -= ElementScrollViewer_ManipulationStarted; //ElementScrollViewer.ManipulationCompleted -= viewer_ManipulationCompleted; ElementScrollViewer.RemoveHandler(ManipulationStartedEvent, new EventHandler<ManipulationStartedEventArgs>(this.ElementScrollViewer_ManipulationStarted)); ElementScrollViewer.RemoveHandler(ManipulationCompletedEvent, new EventHandler<ManipulationCompletedEventArgs>(this.viewer_ManipulationCompleted)); } ElementScrollViewer = GetTemplateChild("ScrollViewer") as Windows.UI.Xaml.Controls.ScrollViewer; if (ElementScrollViewer != null) { ElementScrollViewer.DragEnter += ElementScrollViewer_DragEnter; //ElementScrollViewer.MouseMove += viewer_MouseMove; //ElementScrollViewer.ManipulationStarted += ElementScrollViewer_ManipulationStarted; //ElementScrollViewer.ManipulationCompleted += viewer_ManipulationCompleted; ElementScrollViewer.AddHandler(ManipulationStartedEvent, new EventHandler<ManipulationStartedEventArgs>(this.ElementScrollViewer_ManipulationStarted), true); ElementScrollViewer.AddHandler(ManipulationCompletedEvent, new EventHandler<ManipulationCompletedEventArgs>(this.viewer_ManipulationCompleted), true); } ElementRelease = GetTemplateChild("ReleaseElement") as UIElement; StateDescription = GetTemplateChild("StateDescription") as TextBlock; UpdateDescription = GetTemplateChild("UpdateDescription") as TextBlock; ChangeVisualState(RefreshState.Pulling, false); //GoToState("Pulling", false); }