private static void setText(ExtendedTextBox textBox, string text, bool evenIfFocused)
 {
     if (evenIfFocused || !textBox.IsKeyboardFocused)
     {
         textBox.SetText(text);
     }
 }
 private static void setTime(ExtendedTextBox textBox, string time, bool evenIfFocused)
 {
     if (evenIfFocused ||
         !textBox.IsKeyboardFocused ||
         textBox.Tag == null ||
         textBox.Text == (textBox.Tag as string))
     {
         textBox.SetText(time);
         textBox.Tag = time;
     }
 }
        private void initialise()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            if (this.textbox != null)
            {
                throw new Exception("Auto completion popup cannot be initialised more than once.");
            }

            this.textbox = this.TextBox;

            if (this.textbox == null)
            {
                throw new Exception("Auto completion popup must have a valid text box.");
            }

            this.textbox.PreviewKeyDown    += this.textboxOnPreviewKeyDown;
            this.textbox.TextChanged       += this.textboxOnTextChanged;
            this.textbox.LostKeyboardFocus += (sender, args) =>
            {
                if (this.textbox.Focusable && this.textbox.IsEnabled)
                {
                    var element = Keyboard.FocusedElement as FrameworkElement;
                    while (true)
                    {
                        if (element == null)
                        {
                            break;
                        }

                        if (element == this)
                        {
                            this.textbox.Focus();
                            return;
                        }

                        element = element.Parent as FrameworkElement;
                    }
                }

                this.close();
            };
        }
 private static void setTime(ExtendedTextBox textBox, string time, bool evenIfFocused)
 {
     if (evenIfFocused
         || !textBox.IsKeyboardFocused
         || textBox.Text == (textBox.Tag as string))
     {
         textBox.SetText(time);
         textBox.Tag = time;
     }
 }
 private static void setText(ExtendedTextBox textBox, string text, bool evenIfFocused)
 {
     if (evenIfFocused || !textBox.IsKeyboardFocused)
     {
         textBox.SetText(text);
     }
 }
        private void initialise()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            if (this.textbox != null)
            {
                throw new Exception("Auto completion popup cannot be initialised more than once.");
            }

            this.textbox = this.TextBox;

            if (this.textbox == null)
            {
                throw new Exception("Auto completion popup must have a valid text box.");
            }

            this.textbox.PreviewKeyDown    += this.textboxOnPreviewKeyDown;
            this.textbox.TextChanged       += this.textboxOnTextChanged;
            this.textbox.LostKeyboardFocus += (sender, args) =>
            {
                if (this.textbox.Focusable && this.textbox.IsEnabled)
                {
                    var isKeyboardFocusWithin = popup.IsKeyboardFocusWithin;
                    if (isKeyboardFocusWithin)
                    {
                        if (listBox.IsKeyboardFocusWithin)
                        {
                            this.textbox.Focus();
                        }
                        return;
                    }
                }

                this.close();
            };
            this.popup.LostKeyboardFocus += (sender, args) =>
            {
                if (!this.textbox.IsKeyboardFocusWithin && !this.popup.IsKeyboardFocusWithin)
                {
                    this.close();
                }
            };
            this.popup.PreviewKeyDown += (sender, args) =>
            {
                if (args.Key == Key.Tab)
                {
                    if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    {
                        this.textbox.Focus();
                        args.Handled = true;
                    }
                    else
                    {
                        if (this.textbox.PredictFocus(FocusNavigationDirection.Down) is UIElement nextElement)
                        {
                            Keyboard.Focus(nextElement);
                            args.Handled = true;
                        }
                    }
                }
                else if (args.Key == Key.Down || args.Key == Key.Up || args.Key == Key.Escape)
                {
                    this.textbox.Focus();
                    args.Handled = true;
                }
            };
        }
        private void initialise()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;

            if (this.textbox != null)
                throw new Exception("Auto completion popup cannot be initialised more than once.");

            this.textbox = this.TextBox;

            if (this.textbox == null)
                throw new Exception("Auto completion popup must have a valid text box.");

            this.textbox.PreviewKeyDown += this.textboxOnPreviewKeyDown;
            this.textbox.TextChanged += this.textboxOnTextChanged;
            this.textbox.LostKeyboardFocus += (sender, args) =>
            {
                if (this.textbox.Focusable && this.textbox.IsEnabled)
                {
                    var element = Keyboard.FocusedElement as FrameworkElement;
                    while (true)
                    {
                        if (element == null)
                            break;

                        if (element == this)
                        {
                            this.textbox.Focus();
                            return;
                        }

                        element = element.Parent as FrameworkElement;
                    }
                }

                this.close();
            };
        }