public void Next_Once_Moves_To_Next_Container()
        {
            Button current;
            Button next;

            var top = new StackPanel
            {
                Children = new Controls
                {
                    new StackPanel
                    {
                        [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
                        Children = new Controls
                        {
                            new Button {
                                Name = "Button1"
                            },
                            (current = new Button {
                                Name = "Button2"
                            }),
                            new Button {
                                Name = "Button3"
                            },
                        }
                    },
                    new StackPanel
                    {
                        Children = new Controls
                        {
                            (next = new Button {
                                Name = "Button4"
                            }),
                            new Button {
                                Name = "Button5"
                            },
                            new Button {
                                Name = "Button6"
                            },
                        }
                    },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);

            Assert.Equal(next, result);
        }
        public void Previous_Contained_Returns_Previous_Control_In_Container()
        {
            Button current;
            Button next;

            var top = new StackPanel
            {
                Children = new Controls
                {
                    new StackPanel
                    {
                        [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
                        Children = new Controls
                        {
                            (next = new Button {
                                Name = "Button1"
                            }),
                            (current = new Button {
                                Name = "Button2"
                            }),
                            new Button {
                                Name = "Button3"
                            },
                        }
                    },
                    new StackPanel
                    {
                        Children = new Controls
                        {
                            new Button {
                                Name = "Button4"
                            },
                            new Button {
                                Name = "Button5"
                            },
                            new Button {
                                Name = "Button6"
                            },
                        }
                    },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);

            Assert.Equal(next, result);
        }
        public void Previous_Cycle_Wraps_To_Last()
        {
            Button current;
            Button next;

            var top = new StackPanel
            {
                Children = new Controls
                {
                    new StackPanel
                    {
                        [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
                        Children = new Controls
                        {
                            (current = new Button {
                                Name = "Button1"
                            }),
                            new Button {
                                Name = "Button2"
                            },
                            (next = new Button {
                                Name = "Button3"
                            }),
                        }
                    },
                    new StackPanel
                    {
                        Children = new Controls
                        {
                            new Button {
                                Name = "Button4"
                            },
                            new Button {
                                Name = "Button5"
                            },
                            new Button {
                                Name = "Button6"
                            },
                        }
                    },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);

            Assert.Equal(next, result);
        }
Exemple #4
0
        public void Previous_Once_Moves_To_First_Element()
        {
            Button current;
            Button next;

            var top = new StackPanel
            {
                Children =
                {
                    new StackPanel
                                       {
                                       [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
                                       Children =
                                       {
                                       (next    = new Button{
                                Name = "Button1"
                            }),
                                       new Button {
                                           Name = "Button2"
                                       },
                                       new Button {
                                           Name = "Button3"
                                       },
                                       }
                                       },
                    new StackPanel
                                       {
                                       Children =
                                       {
                                       (current = new Button {
                                Name = "Button4"
                            }),
                                       new Button {
                                           Name = "Button5"
                                       },
                                       new Button {
                                           Name = "Button6"
                                       },
                                       }
                                       },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);

            Assert.Equal(next, result);
        }
Exemple #5
0
        public void Previous_Continue_Returns_Last_Control_In_Previous_Sibling_Container()
        {
            Button current;
            Button next;

            var top = new StackPanel
            {
                Children =
                {
                    new StackPanel
                    {
                        Children =
                        {
                            new Button {
                                Name = "Button1"
                            },
                            new Button {
                                Name = "Button2"
                            },
                            (next = new Button{
                                Name = "Button3"
                            }),
                        }
                    },
                    new StackPanel
                    {
                        Children =
                        {
                            (current = new Button{
                                Name = "Button4"
                            }),
                            new Button {
                                Name = "Button5"
                            },
                            new Button {
                                Name = "Button6"
                            },
                        }
                    },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);

            Assert.Equal(next, result);
        }
Exemple #6
0
        public void Next_Contained_Stops_At_End()
        {
            Button current;

            var top = new StackPanel
            {
                Children =
                {
                    new StackPanel
                                       {
                                       [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
                                       Children =
                                       {
                                       new Button {
                                           Name = "Button1"
                                       },
                                       new Button {
                                           Name = "Button2"
                                       },
                                       (current = new Button {
                                Name = "Button3"
                            }),
                                       }
                                       },
                    new StackPanel
                                       {
                                       Children =
                                       {
                                       new Button {
                                           Name = "Button4"
                                       },
                                       new Button {
                                           Name = "Button5"
                                       },
                                       new Button {
                                           Name = "Button6"
                                       },
                                       }
                                       },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);

            Assert.Null(result);
        }
Exemple #7
0
        public void Previous_Continue_Returns_Parent()
        {
            Button current;

            var top = new Decorator
            {
                Focusable = true,
                Child     = current = new Button
                {
                    Name = "Button",
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);

            Assert.Equal(top, result);
        }
        public void Previous_Contained_Stops_At_Beginning()
        {
            Button current;

            var top = new StackPanel
            {
                Children = new Controls
                {
                    new StackPanel
                    {
                        [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
                        Children = new Controls
                        {
                            (current = new Button {
                                Name = "Button1"
                            }),
                            new Button {
                                Name = "Button2"
                            },
                            new Button {
                                Name = "Button3"
                            },
                        }
                    },
                    new StackPanel
                    {
                        Children = new Controls
                        {
                            new Button {
                                Name = "Button4"
                            },
                            new Button {
                                Name = "Button5"
                            },
                            new Button {
                                Name = "Button6"
                            },
                        }
                    },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);

            Assert.Null(result);
        }
        public void Down_Continue_Returns_Child_Of_Top_Level()
        {
            Button next;

            var top = new StackPanel
            {
                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                Children =
                {
                    (next = new Button { Name = "Button1" }),
                }
            };

            var result = KeyboardNavigationHandler.GetNext(top, NavigationDirection.Down);

            Assert.Equal(next, result);
        }
        public void Focusable_Controls_In_Popup_Should_Get_Focus()
        {
            using (CreateServicesWithFocus())
            {
                var window = PreparedWindow();

                var tb = new TextBox();
                var b  = new Button();
                var p  = new Popup
                {
                    PlacementTarget = window,
                    Child           = new StackPanel
                    {
                        Children =
                        {
                            tb,
                            b
                        }
                    }
                };
                ((ISetLogicalParent)p).SetParent(p.PlacementTarget);
                window.Show();

                p.Open();

                if (p.Host is OverlayPopupHost host)
                {
                    //Need to measure/arrange for visual children to show up
                    //in OverlayPopupHost
                    host.Measure(Size.Infinity);
                    host.Arrange(new Rect(host.DesiredSize));
                }

                tb.Focus();

                Assert.True(FocusManager.Instance?.Current == tb);

                //Ensure focus remains in the popup
                var nextFocus = KeyboardNavigationHandler.GetNext(FocusManager.Instance.Current, NavigationDirection.Next);

                Assert.True(nextFocus == b);

                p.Close();
            }
        }
        public void Up_Continue_Returns_Parent()
        {
            Button current;

            var top = new Decorator
            {
                Focusable = true,
                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                Child = current = new Button
                {
                    Name = "Button",
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Up);

            Assert.Equal(top, result);
        }
Exemple #12
0
        public void Next_Continue_Returns_Child_Of_Top_Level()
        {
            Button next;

            var top = new StackPanel
            {
                Children = new Controls
                {
                    (next = new Button {
                        Name = "Button1"
                    }),
                }
            };

            var result = KeyboardNavigationHandler.GetNext(top, FocusNavigationDirection.Next);

            Assert.Equal(next, result);
        }
        public void Down_Continue_Wraps()
        {
            Button current;
            Button next;

            var top = new StackPanel
            {
                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                Children =
                {
                    new StackPanel
                    {
                        [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                        Children =
                        {
                            new StackPanel
                            {
                                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                                Children =
                                {
                                    (next = new Button { Name = "Button1" }),
                                    new Button { Name = "Button2" },
                                    new Button { Name = "Button3" },
                                }
                            },
                        },
                    },
                    new StackPanel
                    {
                        [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                        Children =
                        {
                            new Button { Name = "Button4" },
                            new Button { Name = "Button5" },
                            (current = new Button { Name = "Button6" }),
                        }
                    },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Down);

            Assert.Equal(next, result);
        }
Exemple #14
0
        public void Keyboard_Navigation_Should_Not_Crash_If_Selected_Item_Is_not_In_Tree()
        {
            using (Application())
            {
                var focus      = FocusManager.Instance;
                var navigation = AvaloniaLocator.Current.GetService <IKeyboardNavigationHandler>();
                var data       = CreateTestTreeData();

                var selectedNode = new Node {
                    Value = "Out of Tree Selected Item"
                };

                var target = new TreeView
                {
                    Template     = CreateTreeViewTemplate(),
                    Items        = data,
                    SelectedItem = selectedNode
                };

                var button = new Button();

                var root = new TestRoot
                {
                    Child = new StackPanel
                    {
                        Children = { target, button },
                    }
                };

                CreateNodeDataTemplate(target);
                ApplyTemplates(target);
                ExpandAll(target);

                var item = data[0].Children[0];
                var node = target.ItemContainerGenerator.Index.ContainerFromItem(item);
                Assert.NotNull(node);

                target.SelectedItem = selectedNode;
                node.Focus();
                Assert.Same(node, focus.Current);

                var next = KeyboardNavigationHandler.GetNext(node, NavigationDirection.Previous);
            }
        }
        protected override void OnAttached(CompositeDisposable disposables)
        {
            var hasErrors = AssociatedObject.GetObservable(DataValidationErrors.HasErrorsProperty);
            var text      = AssociatedObject.GetObservable(TextBox.TextProperty);

            hasErrors.Select(_ => Unit.Default)
            .Merge(text.Select(_ => Unit.Default))
            .Throttle(TimeSpan.FromMilliseconds(100))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ =>
            {
                if (AssociatedObject is { } &&
                    !DataValidationErrors.GetHasErrors(AssociatedObject) &&
                    !string.IsNullOrEmpty(AssociatedObject.Text) &&
                    KeyboardNavigationHandler.GetNext(AssociatedObject, NavigationDirection.Next) is { } nextFocus)
                {
                    nextFocus.Focus();
                }
            })
        public void Up_Continue_Returns_Last_Control_In_Up_Nephew_Container()
        {
            Button current;
            Button next;

            var top = new StackPanel
            {
                Children =
                {
                    new StackPanel
                    {
                        Children =
                        {
                            new StackPanel
                            {
                                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                                Children =
                                {
                                    new Button { Name = "Button1" },
                                    new Button { Name = "Button2" },
                                    (next = new Button { Name = "Button3" }),
                                }
                            },
                        },
                    },
                    new StackPanel
                    {
                        [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                        Children =
                        {
                            (current = new Button { Name = "Button4" }),
                            new Button { Name = "Button5" },
                            new Button { Name = "Button6" },
                        }
                    },
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Up);

            Assert.Equal(next, result);
        }
        public void Up_Contained_Doesnt_Return_Child_Control()
        {
            Decorator current;

            var top = new StackPanel
            {
                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Contained,
                Children = new Controls
                {
                    (current = new Decorator
                    {
                        Focusable = true,
                        Child = new Button(),
                    })
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Up);

            Assert.Null(result);
        }
Exemple #18
0
        public void Previous_Contained_Doesnt_Select_Child_Control()
        {
            Decorator current;

            var top = new StackPanel
            {
                [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
                Children = new Controls
                {
                    (current = new Decorator
                    {
                        Focusable = true,
                        Child = new Button(),
                    })
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);

            Assert.Null(result);
        }
        public void Up_Continue_Returns_Last_Child_Of_Sibling()
        {
            StackPanel container;
            Button     current;
            Button     next;

            var top = new StackPanel
            {
                [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                Children = new Controls
                {
                    (container = new StackPanel
                    {
                        [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue,
                        Children = new Controls
                        {
                            new Button {
                                Name = "Button1"
                            },
                            new Button {
                                Name = "Button2"
                            },
                            (next = new Button {
                                Name = "Button3"
                            }),
                        }
                    }),
                    (current = new Button {
                        Name = "Button4"
                    }),
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Up);

            Assert.Equal(next, result);
        }
        public void ShiftTab_Should_Custom_Navigate_From_Outside()
        {
            Button current;
            Button next;
            var    target = new CustomNavigatingStackPanel
            {
                Children =
                {
                    new Button {
                        Content = "Button 1"
                    },
                    new Button {
                        Content = "Button 2"
                    },
                    (next = new Button{
                        Content = "Button 3"
                    }),
                },
                NextControl = next,
            };

            var root = new StackPanel
            {
                [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
                Children =
                {
                    (current    = new Button {
                        Content = "Outside"
                    }),
                    target,
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);

            Assert.Same(next, result);
        }
Exemple #21
0
        public void Next_Skips_Non_TabStop_Siblings()
        {
            Button current;
            Button next;

            var top = new StackPanel
            {
                Children =
                {
                    new StackPanel
                    {
                        Children =
                        {
                            new Button {
                                Name = "Button1"
                            },
                            new Button {
                                Name = "Button2"
                            },
                            (current = new Button{
                                Name = "Button3"
                            }),
                            new Button {
                                Name = "Button4", [KeyboardNavigation.IsTabStopProperty] = false
                            }
                        }
                    },
                    (next = new Button {
                        Name = "Button5"
                    }),
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);

            Assert.Equal(next, result);
        }
        public void Tab_Should_Navigate_Outside_When_Null_Returned_As_Next()
        {
            Button current;
            Button next;
            var    target = new CustomNavigatingStackPanel
            {
                Children =
                {
                    new Button {
                        Content = "Button 1"
                    },
                    (current = new Button{
                        Content = "Button 2"
                    }),
                    new Button {
                        Content = "Button 3"
                    },
                },
            };

            var root = new StackPanel
            {
                [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
                Children =
                {
                    target,
                    (next = new Button {
                        Content = "Outside"
                    }),
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);

            Assert.Same(next, result);
        }
Exemple #23
0
        public void Tab_Should_Custom_Navigate_From_Outside_When_Wrapping()
        {
            Button current;
            Button next;
            var    target = new CustomNavigatingStackPanel
            {
                Children =
                {
                    new Button {
                        Content = "Button 1"
                    },
                    new Button {
                        Content = "Button 2"
                    },
                    (next = new Button{
                        Content = "Button 3"
                    }),
                },
                NextControl = next,
            };

            var root = new StackPanel
            {
                Children =
                {
                    target,
                    (current = new Button {
                        Content = "Outside"
                    }),
                }
            };

            var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);

            Assert.Same(next, result);
        }