Пример #1
0
        private void BuildPopup()
        {
            _groupSelectorPopup = new Popup();

            var bg = (Color)Resources["PhoneBackgroundColor"];

            _border = new Border
            {
                Background = new SolidColorBrush(
                    Color.FromArgb(0xa0, bg.R, bg.G, bg.B))
            };

            GestureListener listener = GestureService.GetGestureListener(_border);

            listener.GestureBegin     += HandleGesture;
            listener.GestureCompleted += HandleGesture;
            listener.DoubleTap        += HandleGesture;
            listener.DragCompleted    += HandleGesture;
            listener.DragDelta        += HandleGesture;
            listener.DragStarted      += HandleGesture;
            listener.Flick            += HandleGesture;
            listener.Hold             += HandleGesture;
            listener.PinchCompleted   += HandleGesture;
            listener.PinchDelta       += HandleGesture;
            listener.PinchStarted     += HandleGesture;
            listener.Tap += HandleGesture;

            _itemsControl = new LongListSelectorItemsControl();
            _itemsControl.ItemTemplate = GroupItemTemplate;
            _itemsControl.ItemsPanel   = GroupItemsPanel;
            _itemsControl.ItemsSource  = ItemsSource;

            _itemsControl.GroupSelected += itemsControl_GroupSelected;

            _groupSelectorPopup.Child = _border;
            ScrollViewer sv = new ScrollViewer()
            {
                HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled
            };

            _border.Child = sv;
            sv.Content    = _itemsControl;

            SetItemsControlSize();
        }
        /// <summary>
        /// This method does all the necessary work to raise a gesture event. It sets the orginal source, does the routing,
        /// handles Handled, and only creates the event args if they are needed.
        /// </summary>
        /// <typeparam name="T">This is the type of event args that will be raised.</typeparam>
        /// <param name="eventGetter">Gets the specific event to raise.</param>
        /// <param name="argsGetter">Lazy creator function for the event args.</param>
        /// <param name="releaseMouseCapture">Indicates whether the mouse capture should be released </param>
        private static void RaiseGestureEvent <T>(
            Func <GestureListener, EventHandler <T> > eventGetter,
            Func <T> argsGetter, bool releaseMouseCapture)
            where T : GestureEventArgs
        {
            T args = null;

            FrameworkElement originalSource = null;
            bool             handled        = false;

            foreach (FrameworkElement element in _elements)
            {
                if (releaseMouseCapture)
                {
                    element.ReleaseMouseCapture();
                }

                if (!handled)
                {
                    if (originalSource == null)
                    {
                        originalSource = element;
                    }

                    GestureListener helper = GestureService.GetGestureListenerInternal(element, false);
                    if (helper != null)
                    {
                        SafeRaise.Raise(eventGetter(helper), element, () =>
                        {
                            if (args == null)
                            {
                                args = argsGetter();
                                args.OriginalSource = originalSource;
                            }
                            return(args);
                        });
                    }

                    if (args != null && args.Handled == true)
                    {
                        handled = true;
                    }
                }
            }
        }
            protected override void ClearContainerForItemOverride(DependencyObject element, object item)
            {
                base.ClearContainerForItemOverride(element, item);

                GestureService.GetGestureListener(element).Tap -= LongListSelectorItemsControl_Tap;
            }