示例#1
0
        private void setIsEnabled(bool value)
        {
            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
            {
                if (value != _isEnabled)
                {
                    var listenEvents = _eventProcessors.SelectMany(ep => ep.ProcessEvents).Union(
                        _inputProcessors.Processors.SelectMany(ip => ip.ProcessEvents))
                                       .Distinct().ToArray();

                    _isEnabled = value;

                    if (_isEnabled)
                    {
                        foreach (var e in listenEvents)
                        {
                            RoutedEventHandler handler = (RoutedEventHandler)(
                                async(o, re) =>
                            {
                                var input = UIInputBase.FromEventArgs(o, re);
                                if (input.IsValid())
                                {
                                    _inputProcessors.Update(ref input);
                                    try
                                    {
                                        await executeAsync(_eventProcessors, e, input,
                                                           pd =>
                                        {
                                            if (pd.IsHandled)
                                            {
                                                re.Handled = true;
                                            }
                                        }
                                                           );
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine(ex);
                                    }
                                }
                            });
                            _registeredHandler.Add(e, handler);
                            Control.AddHandler(e, handler);

                            ScrollViewer.SetPanningMode(Control as DependencyObject, PanningMode.Both);
                        }
                    }
                    else
                    {
                        foreach (var evt in _registeredHandler.Keys)
                        {
                            Control.RemoveHandler(evt, _registeredHandler[evt]);
                        }
                        _registeredHandler.Clear();
                    }
                }
            }));
        }
示例#2
0
        public async void Control_MouseDrag(object sender, InputEventArgs e)
        {
            FrameworkElement control = sender as FrameworkElement;
            var input = UIInputBase.FromEventArgs(sender, e);

            if (await executeAsync(_eventProcessors, UIEventHub.MouseDragEvent, input))
            {
                (_inputProcessors.Processors.First(p => p is DragInputProcessor) as DragInputProcessor).IsDragging = false;
                //await executeAsync(_eventProcessors, UIElement.PreviewMouseUpEvent, input);
            }
        }
示例#3
0
        public async void Control_TouchDrag(object sender, InputEventArgs e)
        {
            FrameworkElement control = sender as FrameworkElement;
            var input = UIInputBase.FromEventArgs(sender, e);

            input.TouchGesture = UITouchGesture.Drag;
            if (await executeAsync(_eventProcessors, UIEventHub.TouchDragEvent, input))
            {
                //(_inputProcessors.Processors.First(p => p is DragInputProcessor) as DragInputProcessor).IsDragging = false;
            }
        }
示例#4
0
        public void UIEventHub_Handler(object o, RoutedEventArgs e)
        {
            //Create an UIInput from event.
            IUIInput input = UIInputBase.FromEventArgs(o, e as InputEventArgs);

            if (cbEvent.IsChecked.Value && input.InputState != UIInputState.NotApplied)
            {
                addOutput(input.ToString());
            }

            //Use inputprocessors to process the input
            _inputProcessors.Update(ref input);

            if (cbClickCount.IsChecked.Value && input.ClickCount > 1)
            {
                addOutput("ClickCount " + input.ClickCount.ToString());
            }

            if (cbTouchGesture.IsChecked.Value && input.TouchGesture != UITouchGesture.NotApplied && input.TouchGesture != UITouchGesture.Drag)
            {
                addOutput(input.TouchGesture.ToString());
            }

            if (cbRawEvent.IsChecked.Value)
            {
                if (e is MouseButtonEventArgs)
                {
                    MouseButtonEventArgs me = e as MouseButtonEventArgs;
                    addOutput(String.Format("{0} : {1} {2}", me.RoutedEvent, me.ChangedButton, me.GetPosition(null)));
                }
                else if (e is MouseEventArgs)
                {
                    MouseEventArgs me = e as MouseEventArgs;
                    addOutput(String.Format("{0} : {1}", me.RoutedEvent, me.GetPosition(null)));
                }
                else if (e is TouchEventArgs)
                {
                    TouchEventArgs te = e as TouchEventArgs;
                    addOutput(String.Format("{0} : {1}", te.RoutedEvent, te.GetTouchPoint(null)));
                }
                else
                {
                    addOutput(e.ToString());
                }
            }
        }