/// <summary>
        /// Returns an observable that wraps the KeyUp event and returns even if
        /// one of the events involved is handled or occurs in a sibling.
        /// </summary>
        /// <param name="that">The element to listen to.</param>
        /// <returns>An observable that wraps the KeyUp event and returns even if
        /// one of the events involved is handled or occurs in a sibling.</returns>
        internal static IObservable <IEvent <KeyEventArgs> > GetKeyUpOnSelfAndSiblingsAlways(this UIElement that)
        {
            IEnumerable <UIElement> popupRoots =
                VisualTreeExtensions.GetVisualDescendants(that)
                .OfType <Popup>()
                .Select(popup => popup.Child)
                .Where(popupRoot => popupRoot != null);

            return
                (popupRoots
                 .Select(popupRoot => popupRoot.GetKeyUpAlways())
                 .Aggregate(that.GetKeyUpAlways(), (left, right) => left.Merge(right)));
        }
        /// <summary>
        /// Returns an observable that returns a SW.DragDropKeyStates value
        /// whenever it changes, even if one of the events involved
        /// is handled or occurs in a sibling.
        /// </summary>
        /// <param name="that">The element to listen to.</param>
        /// <param name="initialState">The initial state SW.DragDropKeyStates.
        /// </param>
        /// <returns>An observable that returns a SW.DragDropKeyStates value
        /// whenever it changes, even if one of the events involved
        /// is handled.</returns>
        internal static IObservable <SW.DragDropKeyStates> GetKeyStateChangedOnSelfAndSiblingsAlways(this UIElement that, SW.DragDropKeyStates initialState)
        {
            IEnumerable <UIElement> popupRoots =
                VisualTreeExtensions.GetVisualDescendants(that)
                .OfType <Popup>()
                .Select(popup => popup.Child)
                .Where(popupRoot => popupRoot != null);

            return(GetKeyStateChanged(
                       popupRoots
                       .Select(popupRoot => popupRoot.GetMouseLeftButtonDownAlways())
                       .Aggregate(that.GetMouseLeftButtonDownAlways(), (left, right) => left.Merge(right)),
                       popupRoots
                       .Select(popupRoot => popupRoot.GetMouseLeftButtonUpAlways())
                       .Aggregate(that.GetMouseLeftButtonUpAlways(), (left, right) => left.Merge(right)),
                       popupRoots
                       .Select(popupRoot => popupRoot.GetKeyUpAlways())
                       .Aggregate(that.GetKeyUpAlways(), (left, right) => left.Merge(right)),
                       popupRoots
                       .Select(popupRoot => popupRoot.GetKeyDownAlways())
                       .Aggregate(that.GetKeyDownAlways(), (left, right) => left.Merge(right)),
                       initialState));
        }
Esempio n. 3
0
        public override void OnApplyTemplate()
        {
            if (_scrollViewer != null && IsPullToRefreshEnabled)
            {
                _scrollViewer.ManipulationStarted -= OnManipulationStarted;
            }
            if (_top != null)
            {
                _top.MouseLeftButtonDown -= OnJumpToTop;
            }
            if (_bottom != null)
            {
                _bottom.MouseLeftButtonDown -= OnJumpToBottom;
            }

            _ta = null;
            base.OnApplyTemplate();

            if (IsPullToRefreshEnabled)
            {
                SizeChanged += OnSizeChanged;
            }

            _scrollViewer = MoreVisualTreeExtensions.FindFirstChildOfType <ScrollViewer>(this);
            if (null == _scrollViewer)
            {
                return;
                // Must be at design time.
                //throw new NotSupportedException("Control Template must include a ScrollViewer.");
            }

            Dispatcher.BeginInvoke(() =>
            {
                _top    = VisualTreeExtensions.GetVisualDescendants(_scrollViewer).OfType <Rectangle>().Where(b => b.Name == TopJumpName).FirstOrDefault();
                _bottom = VisualTreeExtensions.GetVisualDescendants(_scrollViewer).OfType <Rectangle>().Where(b => b.Name == BottomJumpName).FirstOrDefault();

                if (_top != null)
                {
                    _top.MouseLeftButtonUp += OnJumpToTop;
                }
                if (_bottom != null)
                {
                    _bottom.MouseLeftButtonUp += OnJumpToBottom;
                }
            });

            _header = GetTemplateChild("Header") as ContentPresenter;
            if (_header != null)
            {
                TransformYAnimator.EnsureAnimator(_header, ref _ta);
            }

            if (IsPullToRefreshEnabled)
            {
                _scrollViewer.ManipulationStarted += OnManipulationStarted;
            }

            Dispatcher.BeginInvoke(() =>
            {
                int i         = 0;
                UIElement uie = Parent as UIElement;
                while (i < 8 && uie != null && _piv == null)
                {
                    uie  = VisualTreeHelper.GetParent(uie) as UIElement;
                    _piv = uie as LoadingPivotItem;
                }

                var implroot = VisualTreeHelper.GetChild(_scrollViewer, 0) as FrameworkElement;
                if (implroot != null)
                {
                    VisualStateGroup group = FindVisualState(implroot, "ScrollStates");
                    if (group != null)
                    {
                        group.CurrentStateChanging += OnScrollingStateChanging;
                        // should probably disconnect too
                    }
                }

                this.InvokeOnLayoutUpdated(Bump);
            });
        }
 /// <summary>
 /// Retrieves the items host for a given items control.
 /// </summary>
 /// <param name="itemsControl">The items control.</param>
 /// <returns>The items host for a given items control.</returns>
 protected override Panel GetItemsHost(DataPointSeries itemsControl)
 {
     return(VisualTreeExtensions.GetVisualDescendants(itemsControl).OfType <Panel>().FirstOrDefault());
 }