Skip to content

Commit 529e18b

Browse files
Merge branch 'dotnet:fix-5669' into fix-5669
2 parents 5db5467 + 63af992 commit 529e18b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Core/src/Handlers/SearchBar/SearchBarHandler.Windows.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ protected override void ConnectHandler(AutoSuggestBox platformView)
1717
{
1818
platformView.Loaded += OnLoaded;
1919
platformView.QuerySubmitted += OnQuerySubmitted;
20+
platformView.KeyDown += OnKeyDown;
2021
platformView.TextChanged += OnTextChanged;
2122
}
2223

2324
protected override void DisconnectHandler(AutoSuggestBox platformView)
2425
{
2526
platformView.Loaded -= OnLoaded;
2627
platformView.QuerySubmitted -= OnQuerySubmitted;
28+
platformView.KeyDown -= OnKeyDown;
2729
platformView.TextChanged -= OnTextChanged;
2830
}
2931

@@ -138,6 +140,12 @@ void OnQuerySubmitted(AutoSuggestBox? sender, AutoSuggestBoxQuerySubmittedEventA
138140
VirtualView.SearchButtonPressed();
139141
}
140142

143+
void OnKeyDown(object sender, UI.Xaml.Input.KeyRoutedEventArgs e)
144+
{
145+
if (VirtualView.MaxLength != -1)
146+
PlatformView?.UpdateMaxLength(VirtualView);
147+
}
148+
141149
void OnTextChanged(AutoSuggestBox? sender, AutoSuggestBoxTextChangedEventArgs e)
142150
{
143151
if (e.Reason == AutoSuggestionBoxTextChangeReason.ProgrammaticChange)
@@ -149,4 +157,4 @@ void OnTextChanged(AutoSuggestBox? sender, AutoSuggestBoxTextChangedEventArgs e)
149157
VirtualView.Text = sender.Text;
150158
}
151159
}
152-
}
160+
}

src/Core/src/Platform/Windows/SearchBarExtensions.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Maui.Graphics;
1+
using System;
2+
using Microsoft.Maui.Graphics;
23
using Microsoft.UI.Xaml;
34
using Microsoft.UI.Xaml.Controls;
45
using Microsoft.UI.Xaml.Media;
@@ -132,7 +133,7 @@ public static void UpdateMaxLength(this AutoSuggestBox platformControl, ISearchB
132133

133134
var currentControlText = platformControl.Text;
134135

135-
if (currentControlText.Length > maxLength)
136+
if (currentControlText.Length >= maxLength)
136137
platformControl.Text = currentControlText.Substring(0, maxLength);
137138
}
138139

0 commit comments

Comments
 (0)