public void Direct_Event_Should_Go_Straight_To_Source()
        {
            var ev = new RoutedEvent("test", RoutingStrategies.Direct, typeof(RoutedEventArgs), typeof(TestInteractive));
            var invoked = new List<string>();
            EventHandler<RoutedEventArgs> handler = (s, e) => invoked.Add(((TestInteractive)s).Name);
            var target = CreateTree(ev, handler, RoutingStrategies.Direct);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.Equal(new[] { "2b" }, invoked);
        }
Esempio n. 2
0
        public void Bubbling_Event_Should_Bubble_Up()
        {
            var ev = new RoutedEvent("test", RoutingStrategies.Bubble, typeof(RoutedEventArgs), typeof(TestInteractive));
            var invoked = new List<string>();
            EventHandler<RoutedEventArgs> handler = (s, e) => invoked.Add(((TestInteractive)s).Name);
            var target = this.CreateTree(ev, handler, RoutingStrategies.Bubble | RoutingStrategies.Tunnel);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.Equal(new[] { "2b", "1" }, invoked);
        }
Esempio n. 3
0
        private static void PointerReleased(RoutedEventArgs ev)
        {
            if (ev.Route == RoutingStrategies.Bubble)
            {
                var e = (PointerReleasedEventArgs)ev;

                if (s_lastPress == e.Source)
                {
                    s_lastPress.RaiseEvent(new RoutedEventArgs(TappedEvent));
                }
            }
        }
Esempio n. 4
0
        private static void PointerPressed(RoutedEventArgs ev)
        {
            if (ev.Route == RoutingStrategies.Bubble)
            {
                var e = (PointerPressedEventArgs)ev;

                if (e.ClickCount <= 1)
                {
                    s_lastPress = e.Source;
                }
                else if (e.ClickCount == 2 && s_lastPress == e.Source)
                {
                    e.Source.RaiseEvent(new RoutedEventArgs(DoubleTappedEvent));
                }
            }
        }
        public void Direct_Event_Should_Have_Route_Set_To_Direct()
        {
            var ev = new RoutedEvent("test", RoutingStrategies.Direct, typeof(RoutedEventArgs), typeof(TestInteractive));
            bool called = false;

            EventHandler<RoutedEventArgs> handler = (s, e) =>
            {
                Assert.Equal(RoutingStrategies.Direct, e.Route);
                called = true;
            };

            var target = CreateTree(ev, handler, RoutingStrategies.Direct);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.True(called);
        }
Esempio n. 6
0
        public void Bubbling_Subscription_Should_Not_Catch_Tunneling()
        {
            var ev = new RoutedEvent(
                "test",
                RoutingStrategies.Bubble | RoutingStrategies.Tunnel,
                typeof(RoutedEventArgs),
                typeof(TestInteractive));
            var count = 0;

            EventHandler<RoutedEventArgs> handler = (s, e) =>
            {
                Assert.Equal(RoutingStrategies.Bubble, e.Route);
                ++count;
            };

            var target = this.CreateTree(ev, handler, RoutingStrategies.Bubble);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.Equal(2, count);
        }
Esempio n. 7
0
        /// <summary>
        /// Called when a container raises the <see cref="IsSelectedChangedEvent"/>.
        /// </summary>
        /// <param name="e">The event.</param>
        private void ContainerSelectionChanged(RoutedEventArgs e)
        {
            if (!_ignoreContainerSelectionChanged)
            {
                var selectable = (ISelectable)e.Source;

                if (selectable != null)
                {
                    UpdateSelectionFromEventSource(e.Source, selectable.IsSelected);
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Called when a submenu is clicked somewhere in the menu.
 /// </summary>
 /// <param name="e">The event args.</param>
 private void OnMenuClick(RoutedEventArgs e)
 {
     Close();
     FocusManager.Instance.Focus(null);
     e.Handled = true;
 }
Esempio n. 9
0
 /// <summary>
 /// Called when the menu loses focus.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected override void OnLostFocus(RoutedEventArgs e)
 {
     base.OnLostFocus(e);
     SelectedItem = null;
 }
Esempio n. 10
0
        /// <summary>
        /// Called when the selection on a child item changes.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void ItemIsSelectedChanged(RoutedEventArgs e)
        {
            var selectable = e.Source as ISelectable;

            if (selectable != null && selectable != this && selectable.IsSelected)
            {
                var container = this.ItemContainerGenerator.GetItemForContainer((Control)selectable);

                if (container != null)
                {
                    this.SelectedItem = container;
                    e.Handled = true;
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Global handler for pointer pressed events.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void OnPreviewPointerPressed(object sender, RoutedEventArgs e)
        {
            if (sender == e.Source)
            {
                var ev = (PointerPressEventArgs)e;
                var element = (ev.Device.Captured as IInputElement) ?? (e.Source as IInputElement);

                if (element == null || !CanFocus(element))
                {
                    element = element.GetSelfAndVisualAncestors()
                        .OfType<IInputElement>()
                        .FirstOrDefault(x => CanFocus(x));
                }

                if (element != null)
                {
                    this.Focus(element);
                }
            }
        }
Esempio n. 12
0
        public void Events_Should_Have_Route_Set()
        {
            var ev = new RoutedEvent(
                "test",
                RoutingStrategies.Bubble | RoutingStrategies.Tunnel,
                typeof(RoutedEventArgs),
                typeof(TestInteractive));
            var invoked = new List<RoutingStrategies>();
            EventHandler<RoutedEventArgs> handler = (s, e) => invoked.Add(e.Route);
            var target = this.CreateTree(ev, handler, RoutingStrategies.Bubble | RoutingStrategies.Tunnel);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.Equal(new[]
            {
                RoutingStrategies.Tunnel,
                RoutingStrategies.Tunnel,
                RoutingStrategies.Bubble,
                RoutingStrategies.Bubble,
            },
            invoked);
        }
Esempio n. 13
0
        /// <summary>
        /// Raises the <see cref="Click"/> event.
        /// </summary>
        private void RaiseClickEvent()
        {
            RoutedEventArgs click = new RoutedEventArgs
            {
                RoutedEvent = ClickEvent,
            };

            this.RaiseEvent(click);
        }
Esempio n. 14
0
        /// <summary>
        /// Called when a submenu is opened on this MenuItem or a child MenuItem.
        /// </summary>
        /// <param name="e">The event args.</param>
        protected virtual void OnSubmenuOpened(RoutedEventArgs e)
        {
            var menuItem = e.Source as MenuItem;

            if (menuItem != null && menuItem.Parent == this)
            {
                foreach (var child in this.Items.OfType<MenuItem>())
                {
                    if (child != menuItem && child.IsSubMenuOpen)
                    {
                        child.IsSubMenuOpen = false;
                    }
                }
            }
        }
Esempio n. 15
0
        public void Direct_Class_Handlers_Should_Be_Called()
        {
            var ev = new RoutedEvent(
                "test",
                RoutingStrategies.Direct,
                typeof(RoutedEventArgs),
                typeof(TestInteractive));
            var invoked = new List<string>();
            EventHandler<RoutedEventArgs> handler = (s, e) => invoked.Add(((TestInteractive)s).Name);

            var target = this.CreateTree(ev, null, 0);

            ev.AddClassHandler(typeof(TestInteractive), handler, RoutingStrategies.Direct);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.Equal(new[] { "2b" }, invoked);
        }
Esempio n. 16
0
        /// <summary>
        /// Global handler for pointer pressed events.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void OnPreviewPointerPressed(object sender, RoutedEventArgs e)
        {
            if (sender == e.Source)
            {
                var ev = (PointerPressedEventArgs)e;
                var element = (ev.Device.Captured as IInputElement) ?? (e.Source as IInputElement);

                if (element == null || !CanFocus(element))
                {
                    element = element.GetSelfAndVisualAncestors()
                        .OfType<IInputElement>()
                        .FirstOrDefault(CanFocus);
                }

                if (element != null)
                {
                    Focus(element, NavigationMethod.Pointer, ev.InputModifiers);
                }
            }
        }
Esempio n. 17
0
 public void ClassHandler(RoutedEventArgs e)
 {
     this.ClassHandlerInvoked = true;
 }
Esempio n. 18
0
        public void Typed_Class_Handlers_Should_Be_Called()
        {
            var ev = new RoutedEvent<RoutedEventArgs>(
                "test",
                RoutingStrategies.Bubble | RoutingStrategies.Tunnel,
                typeof(TestInteractive));

            var target = this.CreateTree(ev, null, 0);

            ev.AddClassHandler<TestInteractive>(x => x.ClassHandler, RoutingStrategies.Bubble);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.True(target.ClassHandlerInvoked);
            Assert.True(target.GetVisualParent<TestInteractive>().ClassHandlerInvoked);
        }
Esempio n. 19
0
        public void Event_Should_Should_Keep_Propogating_To_HandedEventsToo_Handlers()
        {
            var ev = new RoutedEvent(
                "test",
                RoutingStrategies.Bubble | RoutingStrategies.Tunnel,
                typeof(RoutedEventArgs),
                typeof(TestInteractive));
            var invoked = new List<string>();

            EventHandler<RoutedEventArgs> handler = (s, e) =>
            {
                invoked.Add(((TestInteractive)s).Name);
                e.Handled = true;
            };

            var target = this.CreateTree(ev, handler, RoutingStrategies.Bubble | RoutingStrategies.Tunnel, true);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.Equal(new[] { "1", "2b", "2b", "1" }, invoked);
        }
Esempio n. 20
0
 protected override void OnLostFocus(RoutedEventArgs e)
 {
     base.OnLostFocus(e);
     SelectionStart = 0;
     SelectionEnd = 0;
     _presenter.HideCaret();
 }
Esempio n. 21
0
 protected override void OnClick(RoutedEventArgs e)
 {
     Toggle();
 }
Esempio n. 22
0
        /// <summary>
        /// Called when a container raises the <see cref="IsSelectedChangedEvent"/>.
        /// </summary>
        /// <param name="e">The event.</param>
        private void ContainerSelectionChanged(RoutedEventArgs e)
        {
            var selectable = (ISelectable)e.Source;

            if (selectable != null)
            {
                TrySetSelectionFromContainerEvent(e.Source, selectable.IsSelected);
            }
        }
Esempio n. 23
0
 /// <summary>
 /// Called when the <see cref="MenuItem"/> is clicked.
 /// </summary>
 /// <param name="e">The click event args.</param>
 protected virtual void OnClick(RoutedEventArgs e)
 {
     if (this.Command != null)
     {
         this.Command.Execute(this.CommandParameter);
     }
 }
Esempio n. 24
0
        public void Handled_Tunnelled_Event_Should_Not_Propogate_Further()
        {
            var ev = new RoutedEvent(
                "test",
                RoutingStrategies.Bubble | RoutingStrategies.Tunnel, 
                typeof(RoutedEventArgs), 
                typeof(TestInteractive));
            var invoked = new List<string>();

            EventHandler<RoutedEventArgs> handler = (s, e) =>
            {
                var t = (TestInteractive)s;
                invoked.Add(t.Name);
                e.Handled = t.Name == "2b";
            };

            var target = CreateTree(ev, handler, RoutingStrategies.Bubble | RoutingStrategies.Tunnel);

            var args = new RoutedEventArgs(ev, target);
            target.RaiseEvent(args);

            Assert.Equal(new[] { "1", "2b" }, invoked);
        }
Esempio n. 25
0
        /// <summary>
        /// Called when the menu item's access key is pressed.
        /// </summary>
        /// <param name="e">The event args.</param>
        private void AccessKeyPressed(RoutedEventArgs e)
        {
            if (this.HasSubMenu)
            {
                this.SelectedIndex = 0;
                this.IsSubMenuOpen = true;
            }
            else
            {
                this.RaiseEvent(new RoutedEventArgs(ClickEvent));
            }

            e.Handled = true;
        }
Esempio n. 26
0
 /// <summary>
 /// Called when the <see cref="MenuItem"/> is clicked.
 /// </summary>
 /// <param name="e">The click event args.</param>
 protected virtual void OnClick(RoutedEventArgs e)
 {
     Command?.Execute(CommandParameter);
 }
Esempio n. 27
0
 /// <summary>
 /// Called before the <see cref="LostFocus"/> event occurs.
 /// </summary>
 /// <param name="e">The event args.</param>
 protected virtual void OnLostFocus(RoutedEventArgs e)
 {
     IsFocused = false;
 }
Esempio n. 28
0
 protected virtual void OnLostFocus(RoutedEventArgs e)
 {
     this.IsFocused = false;
     this.SetValue(IsTabFocusedProperty, false);
 }