Provides helper methods to work with ItemsControl.
Пример #1
0
        /// <summary>
        /// Go through all the items that were not visible on the page and set their properties accordingly without animation.
        /// </summary>
        private void UpdateOutOfViewItems()
        {
            IList <WeakReference> itemsInView = ItemsControlExtensions.GetItemsInViewPort(Picker);

            for (int k = 0; k < Picker.Items.Count; k++)
            {
                FrameworkElement item = (FrameworkElement)Picker.ItemContainerGenerator.ContainerFromIndex(k);

                if (item != null)
                {
                    bool found = false;
                    foreach (WeakReference refr in itemsInView)
                    {
                        if (refr.Target == item)
                        {
                            found = true;
                        }
                    }

                    if (!found)
                    {
                        item.Opacity = (IsOpen) ? 1 : 0;
                        PlaneProjection p = item.Projection as PlaneProjection;
                        if (null != p)
                        {
                            p.RotationX = 0;
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Triggers the visual state changes and visual transitions
        /// to close the list out of selection mode.
        /// </summary>
        private void CloseSelection()
        {
            IList <WeakReference> items = ItemsControlExtensions.GetItemsInViewPort(this);

            //Only animate the containers in the view port.
            foreach (var i in items)
            {
                MultiselectItem item = (MultiselectItem)(((WeakReference)i).Target);
                item.State = SelectionEnabledState.Closed;
                item.UpdateVisualState(true);
            }

            Dispatcher.BeginInvoke(() =>
            {
                for (int j = 0; j < this.Items.Count; j++)
                {
                    MultiselectItem item = (MultiselectItem)ItemContainerGenerator.ContainerFromIndex(j);
                    if (item != null)
                    {
                        item.State = SelectionEnabledState.Closed;
                        item.UpdateVisualState(false);
                    }
                }
            });
        }
Пример #3
0
        private void SetupListItems(double degree)
        {
            _itemsToAnimate = ItemsControlExtensions.GetItemsInViewPort(Picker);

            for (int i = 0; i < _itemsToAnimate.Count; i++)
            {
                FrameworkElement item = (FrameworkElement)_itemsToAnimate[i].Target;
                if (null != item)
                {
                    PlaneProjection p = (PlaneProjection)item.Projection;
                    if (null == p)
                    {
                        p = new PlaneProjection();
                        item.Projection = p;
                    }
                    p.RotationX = degree;
                }
            }
        }
Пример #4
0
        private void UpdateVisualState(bool useTransitions)
        {
            if (useTransitions)
            {
                if (!IsOpen)
                {
                    SetupListItems(0);
                }

                Storyboard mainBoard = new Storyboard();

                Storyboard headerBoard = AnimationForElement(HeaderTitle, 0);
                mainBoard.Children.Add(headerBoard);

                IList <WeakReference> itemsInView = ItemsControlExtensions.GetItemsInViewPort(Picker);
                for (int i = 0; i < itemsInView.Count; i++)
                {
                    FrameworkElement element = (FrameworkElement)itemsInView[i].Target;
                    Storyboard       board   = AnimationForElement(element, i + 1);
                    mainBoard.Children.Add(board);
                }

                Dispatcher.BeginInvoke(UpdateOutOfViewItems);

                if (!IsOpen)
                {
                    mainBoard.Completed += OnClosedStoryboardCompleted;
                }

                mainBoard.Begin();
            }
            else if (!IsOpen)
            {
                OnClosedStoryboardCompleted(null, null);
            }
        }
Пример #5
0
        /// <summary>
        /// Returns the set of weak references to the items
        /// that must be animated.
        /// </summary>
        /// <returns>
        /// A set of weak references to items sorted by their feathering index.
        /// </returns>
        private static IList <WeakReference> GetTargetsToAnimate()
        {
            List <WeakReference>  references;
            List <WeakReference>  targets = new List <WeakReference>();
            PhoneApplicationPage  page    = null;
            PhoneApplicationFrame frame   = Application.Current.RootVisual as PhoneApplicationFrame;

            if (frame != null)
            {
                page = frame.Content as PhoneApplicationPage;
            }

            if (page == null)
            {
                return(null);
            }

            if (!_pagesToReferences.TryGetValue(page, out references))
            {
                return(null);
            }

            foreach (WeakReference r in references)
            {
                FrameworkElement target = r.Target as FrameworkElement;

                // If target is null, skip.
                if (target == null)
                {
                    continue;
                }

                // If target is not on the screen, skip.
                if (!IsOnScreen(target))
                {
                    continue;
                }

                ListBox          listBox          = r.Target as ListBox;
                LongListSelector longListSelector = r.Target as LongListSelector;
                Pivot            pivot            = r.Target as Pivot;

                if (listBox != null)
                {
                    // If the target is a ListBox, feather its items individually.
                    ItemsControlExtensions.GetItemsInViewPort(listBox, targets);
                }
                else if (longListSelector != null)
                {
#if WP7
                    // If the target is a LongListSelector, feather its items individually.
                    ListBox child = TemplatedVisualTreeExtensions.GetFirstLogicalChildByType <ListBox>(longListSelector, false);

                    if (child != null)
                    {
                        ItemsControlExtensions.GetItemsInViewPort(child, targets);
                    }
#else
                    LongListSelectorExtensions.GetItemsInViewPort(longListSelector, targets);
#endif
                }
                else if (pivot != null)
                {
                    // If the target is a Pivot, feather the title and the headers individually.
                    ContentPresenter title = TemplatedVisualTreeExtensions.GetFirstLogicalChildByType <ContentPresenter>(pivot, false);

                    if (title != null)
                    {
                        targets.Add(new WeakReference(title));
                    }

                    PivotHeadersControl headers = TemplatedVisualTreeExtensions.GetFirstLogicalChildByType <PivotHeadersControl>(pivot, false);

                    if (headers != null)
                    {
                        targets.Add(new WeakReference(headers));
                    }
                }
                else
                {
                    // Else, feather the target as a whole.
                    targets.Add(r);
                }
            }

            return(targets);
        }
Пример #6
0
        /// <summary>
        /// Gets the template parts and sets event handlers.
        /// </summary>
        public override void OnApplyTemplate()
        {
            _parent = ItemsControlExtensions.GetParentItemsControl <MultiselectList>(this);

            if (_innerHintPanel != null)
            {
                _innerHintPanel.ManipulationStarted   -= HintPanel_ManipulationStarted;
                _innerHintPanel.ManipulationDelta     -= HintPanel_ManipulationDelta;
                _innerHintPanel.ManipulationCompleted -= HintPanel_ManipulationCompleted;
            }

            if (_outterHintPanel != null)
            {
                _outterHintPanel.ManipulationStarted   -= HintPanel_ManipulationStarted;
                _outterHintPanel.ManipulationDelta     -= HintPanel_ManipulationDelta;
                _outterHintPanel.ManipulationCompleted -= HintPanel_ManipulationCompleted;
            }

            if (_outterCover != null)
            {
                _outterCover.Tap -= Cover_Tap;
            }

            _innerHintPanel  = base.GetTemplateChild(InnerHintPanel) as Rectangle;
            _outterHintPanel = base.GetTemplateChild(OutterHintPanel) as Rectangle;
            _outterCover     = base.GetTemplateChild(OutterCover) as Grid;
            _infoPresenter   = base.GetTemplateChild(InfoPresenter) as ContentControl;

            base.OnApplyTemplate();

            if (_innerHintPanel != null)
            {
                _innerHintPanel.ManipulationStarted   += HintPanel_ManipulationStarted;
                _innerHintPanel.ManipulationDelta     += HintPanel_ManipulationDelta;
                _innerHintPanel.ManipulationCompleted += HintPanel_ManipulationCompleted;
            }

            if (_outterHintPanel != null)
            {
                _outterHintPanel.ManipulationStarted   += HintPanel_ManipulationStarted;
                _outterHintPanel.ManipulationDelta     += HintPanel_ManipulationDelta;
                _outterHintPanel.ManipulationCompleted += HintPanel_ManipulationCompleted;
            }


            if (_outterCover != null)
            {
                _outterCover.Tap += Cover_Tap;
            }

            if (ContentInfo == null && _parent != null)
            {
                if (_parent.ItemInfoTemplate != null)
                {
                    _infoPresenter.ContentTemplate = _parent.ItemInfoTemplate;
                    Binding infoBinding = new Binding();
                    this.SetBinding(ContentInfoProperty, infoBinding);
                }
            }

            if (_outterHintPanel != null)
            {
                if (double.IsNaN(HintPanelHeight))
                {
                    _outterHintPanel.VerticalAlignment = VerticalAlignment.Stretch;
                }
                else
                {
                    _outterHintPanel.VerticalAlignment = VerticalAlignment.Top;
                }
            }

            if (_innerHintPanel != null)
            {
                if (double.IsNaN(HintPanelHeight))
                {
                    _innerHintPanel.VerticalAlignment = VerticalAlignment.Stretch;
                }
                else
                {
                    _innerHintPanel.VerticalAlignment = VerticalAlignment.Top;
                }
            }

            UpdateVisualState(false);
        }