From c3f704d770dce62782cf85d99e8f22b12c29fb34 Mon Sep 17 00:00:00 2001 From: Tomas Wegenast Date: Thu, 14 May 2020 10:53:43 -0300 Subject: [PATCH 1/2] Add better Focus capabilities to TextBox based controls --- .../Controls/Autocomplete.cs | 15 ++++++++++ .../Controls/SearchBase.cs | 29 ++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/MaterialDesignExtensions/Controls/Autocomplete.cs b/MaterialDesignExtensions/Controls/Autocomplete.cs index 971ecd82..8bda4467 100644 --- a/MaterialDesignExtensions/Controls/Autocomplete.cs +++ b/MaterialDesignExtensions/Controls/Autocomplete.cs @@ -271,6 +271,21 @@ public Autocomplete() CommandBindings.Add(new CommandBinding(AutocompleteCommands.SelectAutocompleteItemCommand, SelectAutocompleteItemCommandHandler)); } + /// + /// Selects all the text in the autocomplete text box + /// + public void SelectAll() + { + m_searchTextBox.Focus(); + m_searchTextBox.SelectAll(); + } + + /// + /// Attemps to set focus to the autocomplete text box + /// + public new void Focus() + => m_searchTextBox.Focus(); + public override void OnApplyTemplate() { base.OnApplyTemplate(); diff --git a/MaterialDesignExtensions/Controls/SearchBase.cs b/MaterialDesignExtensions/Controls/SearchBase.cs index 12d11f9a..d4917d5c 100644 --- a/MaterialDesignExtensions/Controls/SearchBase.cs +++ b/MaterialDesignExtensions/Controls/SearchBase.cs @@ -1,19 +1,13 @@ -using System; +using MaterialDesignExtensions.Commands.Internal; +using MaterialDesignExtensions.Controllers; +using MaterialDesignExtensions.Model; +using MaterialDesignThemes.Wpf; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Controls.Primitives; using System.Windows.Input; -using MaterialDesignThemes.Wpf; - -using MaterialDesignExtensions.Commands.Internal; -using MaterialDesignExtensions.Controllers; -using MaterialDesignExtensions.Model; - namespace MaterialDesignExtensions.Controls { /// @@ -219,6 +213,21 @@ public override void OnApplyTemplate() m_searchSuggestionsItemsControl = Template.FindName(SearchSuggestionsItemsControlName, this) as ItemsControl; } + /// + /// Selects all the text in the autocomplete text box + /// + public void SelectAll() + { + m_searchTextBox.Focus(); + m_searchTextBox.SelectAll(); + } + + /// + /// Attemps to set focus to the autocomplete text box + /// + public new void Focus() + => m_searchTextBox.Focus(); + protected override void LoadedHandler(object sender, RoutedEventArgs args) { base.LoadedHandler(sender, args); From 93842598924d924b8dbc2e34c0a38efc16cbedc0 Mon Sep 17 00:00:00 2001 From: Tomas Wegenast Date: Thu, 14 May 2020 10:56:45 -0300 Subject: [PATCH 2/2] Reverted to normal --- MaterialDesignExtensions/Controls/Autocomplete.cs | 15 --------------- MaterialDesignExtensions/Controls/SearchBase.cs | 15 --------------- 2 files changed, 30 deletions(-) diff --git a/MaterialDesignExtensions/Controls/Autocomplete.cs b/MaterialDesignExtensions/Controls/Autocomplete.cs index 8bda4467..971ecd82 100644 --- a/MaterialDesignExtensions/Controls/Autocomplete.cs +++ b/MaterialDesignExtensions/Controls/Autocomplete.cs @@ -271,21 +271,6 @@ public Autocomplete() CommandBindings.Add(new CommandBinding(AutocompleteCommands.SelectAutocompleteItemCommand, SelectAutocompleteItemCommandHandler)); } - /// - /// Selects all the text in the autocomplete text box - /// - public void SelectAll() - { - m_searchTextBox.Focus(); - m_searchTextBox.SelectAll(); - } - - /// - /// Attemps to set focus to the autocomplete text box - /// - public new void Focus() - => m_searchTextBox.Focus(); - public override void OnApplyTemplate() { base.OnApplyTemplate(); diff --git a/MaterialDesignExtensions/Controls/SearchBase.cs b/MaterialDesignExtensions/Controls/SearchBase.cs index d4917d5c..46efda93 100644 --- a/MaterialDesignExtensions/Controls/SearchBase.cs +++ b/MaterialDesignExtensions/Controls/SearchBase.cs @@ -213,21 +213,6 @@ public override void OnApplyTemplate() m_searchSuggestionsItemsControl = Template.FindName(SearchSuggestionsItemsControlName, this) as ItemsControl; } - /// - /// Selects all the text in the autocomplete text box - /// - public void SelectAll() - { - m_searchTextBox.Focus(); - m_searchTextBox.SelectAll(); - } - - /// - /// Attemps to set focus to the autocomplete text box - /// - public new void Focus() - => m_searchTextBox.Focus(); - protected override void LoadedHandler(object sender, RoutedEventArgs args) { base.LoadedHandler(sender, args);