From 70cb172874df21c757e23ee35ae5cd405a98f6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Thu, 26 May 2022 13:55:14 +0200 Subject: [PATCH 01/27] Fix Windows SearchBar MaxLength property --- .../SearchBar/SearchBarHandler.Windows.cs | 16 ++++++++++++---- .../src/Platform/Windows/SearchBarExtensions.cs | 6 +++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Core/src/Handlers/SearchBar/SearchBarHandler.Windows.cs b/src/Core/src/Handlers/SearchBar/SearchBarHandler.Windows.cs index b2eb3b8e6411..cb8846947e06 100644 --- a/src/Core/src/Handlers/SearchBar/SearchBarHandler.Windows.cs +++ b/src/Core/src/Handlers/SearchBar/SearchBarHandler.Windows.cs @@ -5,7 +5,7 @@ namespace Microsoft.Maui.Handlers { public partial class SearchBarHandler : ViewHandler - { + { public AutoSuggestBox? QueryEditor => null; protected override AutoSuggestBox CreatePlatformView() => new AutoSuggestBox @@ -18,6 +18,7 @@ protected override void ConnectHandler(AutoSuggestBox platformView) { platformView.Loaded += OnLoaded; platformView.QuerySubmitted += OnQuerySubmitted; + platformView.KeyDown += OnKeyDown; platformView.TextChanged += OnTextChanged; } @@ -25,6 +26,7 @@ protected override void DisconnectHandler(AutoSuggestBox platformView) { platformView.Loaded -= OnLoaded; platformView.QuerySubmitted -= OnQuerySubmitted; + platformView.KeyDown -= OnKeyDown; platformView.TextChanged -= OnTextChanged; } @@ -47,7 +49,7 @@ public static void MapPlaceholder(ISearchBarHandler handler, ISearchBar searchBa { handler.PlatformView?.UpdatePlaceholder(searchBar); } - + public static void MapVerticalTextAlignment(ISearchBarHandler handler, ISearchBar searchBar) { handler.PlatformView?.UpdateVerticalTextAlignment(searchBar); @@ -80,7 +82,7 @@ public static void MapTextColor(ISearchBarHandler handler, ISearchBar searchBar) handler?.PlatformView?.UpdateTextColor(searchBar); } - public static void MapIsTextPredictionEnabled(ISearchBarHandler handler, ISearchBar searchBar) + public static void MapIsTextPredictionEnabled(ISearchBarHandler handler, ISearchBar searchBar) { handler.PlatformView?.UpdateIsTextPredictionEnabled(searchBar); } @@ -125,6 +127,12 @@ void OnQuerySubmitted(AutoSuggestBox? sender, AutoSuggestBoxQuerySubmittedEventA VirtualView.SearchButtonPressed(); } + void OnKeyDown(object sender, UI.Xaml.Input.KeyRoutedEventArgs e) + { + if (VirtualView.MaxLength != -1) + PlatformView?.UpdateMaxLength(VirtualView); + } + void OnTextChanged(AutoSuggestBox? sender, AutoSuggestBoxTextChangedEventArgs e) { if (e.Reason == AutoSuggestionBoxTextChangeReason.ProgrammaticChange) @@ -136,4 +144,4 @@ void OnTextChanged(AutoSuggestBox? sender, AutoSuggestBoxTextChangedEventArgs e) VirtualView.Text = sender.Text; } } -} +} \ No newline at end of file diff --git a/src/Core/src/Platform/Windows/SearchBarExtensions.cs b/src/Core/src/Platform/Windows/SearchBarExtensions.cs index 763857817e72..53ee6e947e44 100644 --- a/src/Core/src/Platform/Windows/SearchBarExtensions.cs +++ b/src/Core/src/Platform/Windows/SearchBarExtensions.cs @@ -106,8 +106,8 @@ public static void UpdateMaxLength(this AutoSuggestBox platformControl, ISearchB var currentControlText = platformControl.Text; - if (currentControlText.Length > maxLength) - platformControl.Text = currentControlText.Substring(0, maxLength); + if (currentControlText.Length >= maxLength) + platformControl.Text = currentControlText.Substring(0, maxLength - 1); } public static void UpdateIsReadOnly(this AutoSuggestBox platformControl, ISearchBar searchBar) @@ -120,4 +120,4 @@ public static void UpdateIsTextPredictionEnabled(this AutoSuggestBox platformCon // AutoSuggestBox does not support this property } } -} +} \ No newline at end of file From 63af99215a74f54cea9720430493938202ea537e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez=20Ruiz?= Date: Thu, 26 May 2022 16:40:05 +0200 Subject: [PATCH 02/27] Fix issue --- src/Core/src/Platform/Windows/SearchBarExtensions.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Windows/SearchBarExtensions.cs b/src/Core/src/Platform/Windows/SearchBarExtensions.cs index 53ee6e947e44..438c5c24cfa3 100644 --- a/src/Core/src/Platform/Windows/SearchBarExtensions.cs +++ b/src/Core/src/Platform/Windows/SearchBarExtensions.cs @@ -1,4 +1,5 @@ -using Microsoft.Maui.Graphics; +using System; +using Microsoft.Maui.Graphics; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; @@ -107,7 +108,7 @@ public static void UpdateMaxLength(this AutoSuggestBox platformControl, ISearchB var currentControlText = platformControl.Text; if (currentControlText.Length >= maxLength) - platformControl.Text = currentControlText.Substring(0, maxLength - 1); + platformControl.Text = currentControlText.Substring(0, maxLength); } public static void UpdateIsReadOnly(this AutoSuggestBox platformControl, ISearchBar searchBar) From 19dc864b5051f1718b55d01bdb0a55ac24bdd22e Mon Sep 17 00:00:00 2001 From: BagavathiPerumal Date: Wed, 25 Sep 2024 12:34:22 +0530 Subject: [PATCH 03/27] fix-5669-Fix for Windows SearchBar MaxLength > 0 not working properly. --- .../TestCases.HostApp/Issues/Issue5669.xaml | 15 ++++++++++ .../Issues/Issue5669.xaml.cs | 18 +++++++++++ .../Tests/Issues/Issue5669.cs | 28 +++++++++++++++++ .../SearchBar/SearchBarHandler.Windows.cs | 30 +++++++++++++++++-- .../Platform/Windows/SearchBarExtensions.cs | 4 ++- .../net-windows/PublicAPI.Unshipped.txt | 2 ++ 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue5669.xaml create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue5669.xaml.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue5669.cs diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue5669.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue5669.xaml new file mode 100644 index 000000000000..b8398fb699c1 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue5669.xaml @@ -0,0 +1,15 @@ + + + + + + + +