PowerArgs.Cli.FocusManager.Add C# (CSharp) Method

Add() public method

Adds the current control to the current focus context
public Add ( ConsoleControl c ) : void
c ConsoleControl The control to add
return void
        public void Add(ConsoleControl c)
        {
            if(focusStack.Peek().Controls.Contains(c))
            {
                throw new InvalidOperationException("Item already being tracked");
            }
            focusStack.Peek().Controls.Add(c);
        }

Usage Example

Example #1
0
        private void ControlAddedToVisualTree(ConsoleControl c)
        {
            c.Application = this;
            c.OnDisposed(() =>
            {
                if (c.Application == this && c.Parent != null && c.Parent.Application == this)
                {
                    if (c.Parent is ConsolePanel)
                    {
                        (c.Parent as ConsolePanel).Controls.Remove(c);
                    }
                    else
                    {
                        throw new NotSupportedException($"You cannot manually dispose child controls of parent type {c.Parent.GetType().Name}");
                    }
                }
            });

            if (c is ConsolePanel)
            {
                var childPanel = c as ConsolePanel;
                childPanel.Controls.SynchronizeForLifetime((cp) => { ControlAddedToVisualTree(cp); }, (cp) => { ControlRemovedFromVisualTree(cp); }, () => { }, c);
            }
            else if (c is ProtectedConsolePanel)
            {
                var childPanel = c as ProtectedConsolePanel;
                ControlAddedToVisualTree(childPanel.ProtectedPanelInternal);
                childPanel.OnDisposed(() => ControlRemovedFromVisualTree(childPanel.ProtectedPanelInternal));
            }

            FocusManager.Add(c);
            c.AddedToVisualTreeInternal();

            ControlAdded.Fire(c);
        }
All Usage Examples Of PowerArgs.Cli.FocusManager::Add