Ejemplo n.º 1
0
        /// <summary>
        /// Creates the <see cref="Panel"/> when <see cref="ApplyTemplate"/> is called for the first
        /// time.
        /// </summary>
        private void CreatePanel()
        {
            ClearVisualChildren();
            Panel = ItemsPanel.Build();
            Panel.SetValue(TemplatedParentProperty, TemplatedParent);

            if (!Panel.IsSet(KeyboardNavigation.DirectionalNavigationProperty))
            {
                KeyboardNavigation.SetDirectionalNavigation(
                    (InputElement)Panel,
                    KeyboardNavigationMode.Contained);
            }

            AddVisualChild(Panel);

            var logicalHost = this.FindReparentingHost();

            if (logicalHost != null)
            {
                ((IReparentingControl)Panel).ReparentLogicalChildren(
                    logicalHost,
                    logicalHost.LogicalChildren);
            }

            KeyboardNavigation.SetTabNavigation(
                (InputElement)Panel,
                KeyboardNavigation.GetTabNavigation(this));
            _createdPanel = true;
            CreateItemsAndListenForChanges(Items);
        }
Ejemplo n.º 2
0
        public void Panel_TabNavigation_Should_Be_Set_To_Once()
        {
            var target = new ItemsPresenter();

            target.ApplyTemplate();

            Assert.Equal(KeyboardNavigationMode.Once, KeyboardNavigation.GetTabNavigation((InputElement)target.Panel));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the focusable descendants of the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="direction">The tab direction. Must be Next or Previous.</param>
        /// <returns>The element's focusable descendants.</returns>
        private static IEnumerable <IInputElement> GetFocusableDescendants(IInputElement element,
                                                                           NavigationDirection direction)
        {
            var mode = KeyboardNavigation.GetTabNavigation((InputElement)element);

            if (mode == KeyboardNavigationMode.None)
            {
                yield break;
            }

            var children = element.GetVisualChildren().OfType <IInputElement>();

            if (mode == KeyboardNavigationMode.Once)
            {
                var active = KeyboardNavigation.GetTabOnceActiveElement((InputElement)element);

                if (active != null)
                {
                    yield return(active);

                    yield break;
                }
                else
                {
                    children = children.Take(1);
                }
            }

            foreach (var child in children)
            {
                var customNext = GetCustomNext(child, direction);

                if (customNext.handled)
                {
                    yield return(customNext.next);
                }
                else
                {
                    if (child.CanFocus() && KeyboardNavigation.GetIsTabStop((InputElement)child))
                    {
                        yield return(child);
                    }

                    if (child.CanFocusDescendants())
                    {
                        foreach (var descendant in GetFocusableDescendants(child, direction))
                        {
                            if (KeyboardNavigation.GetIsTabStop((InputElement)descendant))
                            {
                                yield return(descendant);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        protected override void PanelCreated(IPanel panel)
        {
            Virtualizer?.Dispose();
            Virtualizer = ItemVirtualizer.Create(this);
            ((ILogicalScrollable)this).InvalidateScroll?.Invoke();

            KeyboardNavigation.SetTabNavigation(
                (InputElement)Panel,
                KeyboardNavigation.GetTabNavigation(this));
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        protected override void CreatePanel()
        {
            base.CreatePanel();

            if (!Panel.IsSet(KeyboardNavigation.DirectionalNavigationProperty))
            {
                KeyboardNavigation.SetDirectionalNavigation(
                    (InputElement)Panel,
                    KeyboardNavigationMode.Contained);
            }

            KeyboardNavigation.SetTabNavigation(
                (InputElement)Panel,
                KeyboardNavigation.GetTabNavigation(this));
        }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        protected override void PanelCreated(IPanel panel)
        {
            _virtualizer = ItemVirtualizer.Create(this);
            ((ILogicalScrollable)this).InvalidateScroll?.Invoke();

            if (!Panel.IsSet(KeyboardNavigation.DirectionalNavigationProperty))
            {
                KeyboardNavigation.SetDirectionalNavigation(
                    (InputElement)Panel,
                    KeyboardNavigationMode.Contained);
            }

            KeyboardNavigation.SetTabNavigation(
                (InputElement)Panel,
                KeyboardNavigation.GetTabNavigation(this));
        }
Ejemplo n.º 7
0
        private static void OnIsModalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ModalContentPresenter control = (ModalContentPresenter)d;

            if ((bool)e.NewValue == true)
            {
                /*
                 * Cache the keyboard navigation mode of the primary content before setting it to
                 * 'none' so that it can be restored when the modal content is hidden.
                 */
                control.cachedTabNavigationMode         = KeyboardNavigation.GetTabNavigation(control.primaryContentPresenter);
                control.cachedDirectionalNavigationMode = KeyboardNavigation.GetDirectionalNavigation(control.primaryContentPresenter);
                control.cachedFocusedElement            = Keyboard.FocusedElement;

                KeyboardNavigation.SetTabNavigation(control.primaryContentPresenter, KeyboardNavigationMode.None);
                KeyboardNavigation.SetDirectionalNavigation(control.primaryContentPresenter, KeyboardNavigationMode.None);

                /*
                 * Show the overlay (which in turn shows the modal content as it is a child of
                 * the overlay) and move focus to the first logical element.
                 */
                control.overlay.Visibility = Visibility.Visible;
                control.overlay.MoveFocus(traversalDirection);

                control.RaiseModalContentShownEvents();
            }
            else
            {
                /*
                 * Hide the overlay (which also hides the modal content...).
                 */
                control.overlay.Visibility = Visibility.Hidden;

                /*
                 * Restore the cached keyboard navigation value on the primary content and move
                 * focus to its first logical element.
                 */
                KeyboardNavigation.SetTabNavigation(control.primaryContentPresenter, control.cachedTabNavigationMode);
                KeyboardNavigation.SetDirectionalNavigation(control.primaryContentPresenter, control.cachedDirectionalNavigationMode);

                Keyboard.Focus(control.cachedFocusedElement);

                control.primaryContentPresenter.MoveFocus(traversalDirection);
                control.RaiseModalContentHiddenEvents();
            }
        }
Ejemplo n.º 8
0
        public void Init()
        {
            bool isFirstLaunch = Properties.LauncherSettings.Default.CurrentProfile == "" || Properties.LauncherSettings.Default.IsFirstLaunch;

            MainFrame_KeyboardNavigationMode_Default = KeyboardNavigation.GetTabNavigation(MainThread.MainFrame);

            ConfigManager.Init();
            ConfigManager.OnConfigStateChanged(this, Events.ConfigStateArgs.Empty);

            // show first launch window if no profile
            if (isFirstLaunch)
            {
                SetOverlayFrame(new WelcomePage(), false);
            }
            MainThread.NavigateToMainPage();
            ProgressBarStateChanged += ViewModel_ProgressBarStateChanged;
        }
Ejemplo n.º 9
0
        protected virtual void HandlePreviewTabKey(KeyEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            var dataGridControl = this.ParentDataGridControl;

            if (dataGridControl == null)
            {
                return;
            }

            var dataGridContext = dataGridControl.CurrentContext;

            if (dataGridContext == null)
            {
                return;
            }

            var container = dataGridContext.GetContainerFromItem(dataGridContext.InternalCurrentItem);

            if (container == null)
            {
                return;
            }

            var tabbingMode = KeyboardNavigation.GetTabNavigation(container);

            if (tabbingMode == KeyboardNavigationMode.None)
            {
                return;
            }

            if ((Keyboard.Modifiers == ModifierKeys.None) || (Keyboard.Modifiers == ModifierKeys.Shift))
            {
                DataGridItemsHost.BringIntoViewKeyboardFocusedElement();

                //Force the "inline" relayout of the panel
                //This has no effect if the panel do not have to be updated.
                this.UpdateLayout();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the focusable descendents of the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>The element's focusable descendents.</returns>
        private static IEnumerable <IInputElement> GetFocusableDescendents(IInputElement element)
        {
            var mode = KeyboardNavigation.GetTabNavigation((InputElement)element);

            if (mode == KeyboardNavigationMode.None)
            {
                yield break;
            }

            var children = element.GetVisualChildren().OfType <IInputElement>();

            if (mode == KeyboardNavigationMode.Once)
            {
                var active = KeyboardNavigation.GetTabOnceActiveElement((InputElement)element);

                if (active != null)
                {
                    yield return(active);

                    yield break;
                }
                else
                {
                    children = children.Take(1);
                }
            }

            foreach (var child in children)
            {
                if (child.CanFocus())
                {
                    yield return(child);
                }

                if (child.CanFocusDescendents())
                {
                    foreach (var descendent in GetFocusableDescendents(child))
                    {
                        yield return(descendent);
                    }
                }
            }
        }
Ejemplo n.º 11
0
            public override void OnApplyTemplate()
            {
                base.OnApplyTemplate();

                var dialogShowingStates = GetTemplateChild("DialogShowingStates") as VisualStateGroup;
                var backgroundElement   = GetTemplateChild("BackgroundElement") as FrameworkElement;

                Debug.Assert(dialogShowingStates != null && backgroundElement != null);
                dialogShowingStates.CurrentStateChanged += (s, e) =>
                {
                    //Debug.WriteLine($"OldState: {e.OldState?.Name}, NewState: {e.NewState.Name}");
                    if (e.NewState.Name == "DialogShowing")
                    {
                        Dispatcher.BeginInvoke(() =>
                        {
                            Debug.Assert(KeyboardNavigation.GetTabNavigation(backgroundElement) == KeyboardNavigationMode.Cycle);
                        });
                    }
                };
            }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the next control in the specified tab direction.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="direction">The tab direction. Must be Next or Previous.</param>
        /// <param name="outsideElement">
        /// If true will not descend into <paramref name="element"/> to find next control.
        /// </param>
        /// <returns>
        /// The next element in the specified direction, or null if <paramref name="element"/>
        /// was the last in the requested direction.
        /// </returns>
        public static IInputElement?GetNextInTabOrder(
            IInputElement element,
            NavigationDirection direction,
            bool outsideElement = false)
        {
            element = element ?? throw new ArgumentNullException(nameof(element));

            if (direction != NavigationDirection.Next && direction != NavigationDirection.Previous)
            {
                throw new ArgumentException("Invalid direction: must be Next or Previous.");
            }

            var container = element.GetVisualParent <IInputElement>();

            if (container != null)
            {
                var mode = KeyboardNavigation.GetTabNavigation((InputElement)container);

                switch (mode)
                {
                case KeyboardNavigationMode.Continue:
                    return(GetNextInContainer(element, container, direction, outsideElement) ??
                           GetFirstInNextContainer(element, element, direction));

                case KeyboardNavigationMode.Cycle:
                    return(GetNextInContainer(element, container, direction, outsideElement) ??
                           GetFocusableDescendant(container, direction));

                case KeyboardNavigationMode.Contained:
                    return(GetNextInContainer(element, container, direction, outsideElement));

                default:
                    return(GetFirstInNextContainer(element, container, direction));
                }
            }
            else
            {
                return(GetFocusableDescendants(element, direction).FirstOrDefault());
            }
        }
Ejemplo n.º 13
0
        private void Init()
        {
            this.DataContext    = new LauncherModel();
            updateButton.Click += Updater.UpdateButton_Click;
            MainFrame_KeyboardNavigationMode_Default = KeyboardNavigation.GetTabNavigation(MainFrame);

            Panel.SetZIndex(OverlayFrame, 0);
            Panel.SetZIndex(ErrorFrame, 1);
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            // show first launch window if no profile
            if (Properties.LauncherSettings.Default.CurrentProfile == "" || Properties.LauncherSettings.Default.IsFirstLaunch)
            {
                SetOverlayFrame(new WelcomePage());
            }
            NavigateToPlayScreen();


            ConfigManager.Init();
            ConfigManager.GameManager.GameStateChanged += GameManager_GameStateChanged;
            ConfigManager.ConfigStateChanged           += ConfigManager_ConfigStateChanged;
            ConfigManager.OnConfigStateChanged(this, ConfigManager.ConfigStateArgs.Empty);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the next control in the specified tab direction.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="direction">The tab direction. Must be Next or Previous.</param>
        /// <param name="outsideElement">
        /// If true will not descend into <paramref name="element"/> to find next control.
        /// </param>
        /// <returns>
        /// The next element in the specified direction, or null if <paramref name="element"/>
        /// was the last in the requested direction.
        /// </returns>
        public static IInputElement GetNextInTabOrder(
            IInputElement element,
            NavigationDirection direction,
            bool outsideElement = false)
        {
            Contract.Requires <ArgumentNullException>(element != null);
            Contract.Requires <ArgumentException>(
                direction == NavigationDirection.Next ||
                direction == NavigationDirection.Previous);

            var container = element.GetVisualParent <IInputElement>();

            if (container != null)
            {
                var mode = KeyboardNavigation.GetTabNavigation((InputElement)container);

                switch (mode)
                {
                case KeyboardNavigationMode.Continue:
                    return(GetNextInContainer(element, container, direction, outsideElement) ??
                           GetFirstInNextContainer(element, element, direction));

                case KeyboardNavigationMode.Cycle:
                    return(GetNextInContainer(element, container, direction, outsideElement) ??
                           GetFocusableDescendant(container, direction));

                case KeyboardNavigationMode.Contained:
                    return(GetNextInContainer(element, container, direction, outsideElement));

                default:
                    return(GetFirstInNextContainer(element, container, direction));
                }
            }
            else
            {
                return(GetFocusableDescendants(element, direction).FirstOrDefault());
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates the <see cref="Panel"/> when <see cref="ApplyTemplate"/> is called for the first
        /// time.
        /// </summary>
        private void CreatePanel()
        {
            Panel = ItemsPanel.Build();
            Panel.SetValue(TemplatedParentProperty, TemplatedParent);

            if (!Panel.IsSet(KeyboardNavigation.DirectionalNavigationProperty))
            {
                KeyboardNavigation.SetDirectionalNavigation(
                    (InputElement)Panel,
                    KeyboardNavigationMode.Contained);
            }

            LogicalChildren.Clear();
            VisualChildren.Clear();
            LogicalChildren.Add(Panel);
            VisualChildren.Add(Panel);

            KeyboardNavigation.SetTabNavigation(
                (InputElement)Panel,
                KeyboardNavigation.GetTabNavigation(this));
            _createdPanel = true;
            CreateItemsAndListenForChanges(Items);
        }
        public void Init()
        {
            MainFrame_KeyboardNavigationMode_Default = KeyboardNavigation.GetTabNavigation(MainThread.MainFrame);

            LoadVersions();
            LoadConfig();

            bool isFirstLaunch = Properties.LauncherSettings.Default.CurrentProfile == "" ||
                                 Properties.LauncherSettings.Default.IsFirstLaunch ||
                                 Config.profiles.Count() == 0;

            // show first launch window if no profile
            if (isFirstLaunch)
            {
                SetOverlayFrame_Strict(new WelcomePage());
            }
            MainThread.NavigateToMainPage();
            ProgressBarStateChanged += ViewModel_ProgressBarStateChanged;

            ErrorScreenShow.SetHandler(this);
            DialogPrompt.SetHandler(this);

            ConsoleArgumentManager.PraseArgs(Program.Arguments);
        }
Ejemplo n.º 17
0
    private static void OnIsModalChanged(DependencyObject d,
                                         DependencyPropertyChangedEventArgs e)
    {
        ModalContentPresenter control = (ModalContentPresenter)d;

        if ((bool)e.NewValue == true)
        {
            control.cachedKeyboardNavigationMode =
                KeyboardNavigation.GetTabNavigation(control.primaryContent);
            KeyboardNavigation.SetTabNavigation(
                control.primaryContent, KeyboardNavigationMode.None);
            control.overlay.Visibility = Visibility.Visible;
            control.overlay.MoveFocus(traversalDirection);
            control.RaiseModalContentShownEvents();
        }
        else
        {
            control.overlay.Visibility = Visibility.Hidden;
            KeyboardNavigation.SetTabNavigation(
                control.primaryContent, control.cachedKeyboardNavigationMode);
            control.primaryContent.MoveFocus(traversalDirection);
            control.RaiseModalContentHiddenEvents();
        }
    }