TryFocus() public method

Tries to give this control focus. If the focus is in the visual tree, and is in the current focus layer, and has it's CanFocus property to true then focus should be granted.
public TryFocus ( ) : bool
return bool
Example #1
0
        /// <summary>
        /// Adds the current control to the current focus context
        /// </summary>
        /// <param name="c">The control to add</param>
        internal void Add(ConsoleControl c)
        {
            if (focusStack.Peek().Controls.Contains(c))
            {
                throw new InvalidOperationException("Item already being tracked");
            }
            focusStack.Peek().Controls.Add(c);

            if (c.Id != null && c.Id == currentFocusedControlId)
            {
                c.TryFocus();
            }

            c.SubscribeForLifetime(nameof(c.CanFocus), () =>
            {
                if (c.CanFocus == false && c.HasFocus)
                {
                    TryMoveFocus();
                }
            }, c);
        }