Exemplo n.º 1
0
 public async Task When_VerifyEnabledXYKeyboardNavigation(XYFocusKeyboardNavigationMode mode, VirtualKey key, bool shouldSucceed, int targetIndex)
 {
     await VerifyXYNavigationAsync(
         mode,
         key,
         shouldSucceed,
         targetIndex);
 }
Exemplo n.º 2
0
    private async Task VerifyXYNavigationAsync(XYFocusKeyboardNavigationMode mode, VirtualKey key, bool shouldSucceed, int targetIndex)
    {
        var grid = CreateButtonGrid(mode);

        TestServices.WindowHelper.WindowContent = grid;
        await TestServices.WindowHelper.WaitForIdle();

        var centerButton = (Button)grid.Children[CenterButtonIndex];

        centerButton.Focus(FocusState.Programmatic);

        var inputHandler = new UnoFocusInputHandler(VisualTree.GetRootForElement(centerButton));
        var result       = inputHandler.TryHandleDirectionalFocus(key);

        Assert.AreEqual(shouldSucceed, result);
        if (shouldSucceed)
        {
            var button = grid.Children[targetIndex];
            Assert.AreEqual(button, FocusManager.GetFocusedElement(grid.XamlRoot));
        }
    }
Exemplo n.º 3
0
    private Grid CreateButtonGrid(XYFocusKeyboardNavigationMode navigationMode)
    {
        var grid = new Grid()
        {
            XYFocusKeyboardNavigation = navigationMode
        };

        for (int i = 0; i < 3; i++)
        {
            grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(64)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(64)
            });
        }

        for (int y = 0; y < 3; y++)
        {
            for (int x = 0; x < 3; x++)
            {
                var button = new Button()
                {
                    Content = grid.Children.Count.ToString(),
                    XYFocusKeyboardNavigation = navigationMode,
                };

                grid.Children.Add(button);

                Grid.SetColumn(button, x);
                Grid.SetRow(button, y);
            }
        }

        return(grid);
    }