-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for Windows SearchBar MaxLength > 0 not working properly. #24919
Conversation
if (textbox != null) | ||
textbox!.MaxLength = searchBar.MaxLength; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (textbox != null) | |
textbox!.MaxLength = searchBar.MaxLength; | |
if (textbox is not null) | |
textbox.MaxLength = searchBar.MaxLength; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartyIX, I have modified changes. Could you please validate it once and let me know if there are any further concerns.
…of using FindChildOfType.
var child = platformControl.GetChildren<TextBox>(); | ||
if (child is not null && child.Count() > 0) | ||
{ | ||
child.FirstOrDefault()!.MaxLength = searchBar.MaxLength; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps
var child = platformControl.GetChildren<TextBox>(); | |
if (child is not null && child.Count() > 0) | |
{ | |
child.FirstOrDefault()!.MaxLength = searchBar.MaxLength; | |
} | |
var children = platformControl.GetChildren<TextBox>(); | |
var child = children?.FirstOrDefault(); | |
if (child is not null) | |
{ | |
child.MaxLength = searchBar.MaxLength; | |
} |
-or-
var child = platformControl.GetChildren<TextBox>(); | |
if (child is not null && child.Count() > 0) | |
{ | |
child.FirstOrDefault()!.MaxLength = searchBar.MaxLength; | |
} | |
var child = platformControl.GetChildren<TextBox>()?.FirstOrDefault(); | |
if (child is not null) | |
{ | |
child.MaxLength = searchBar.MaxLength; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartyIX, I have modified changes based on your suggestion. Could you please validate it once and let me know if there are any further concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #24919 (comment). Other than that, it looks OK to me.
@@ -112,6 +112,17 @@ public static void UpdateMaxLength(this AutoSuggestBox platformControl, ISearchB | |||
if (maxLength == -1) | |||
maxLength = int.MaxValue; | |||
|
|||
var child = platformControl.GetChildren<TextBox>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename this to children
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's missing some using the builds is failing
D:\a\1\s\src\Core\src\Platform\Windows\SearchBarExtensions.cs(118,28): error CS1061: 'IEnumerable<TextBox?>' does not contain a definition for 'FirstOrDefault' and no accessible extension method 'FirstOrDefault' accepting a first argument of type 'IEnumerable<TextBox?>' could be found (are you missing a using directive or an assembly reference?) [D:\a\1\s\src\Core\src\Core.csproj::TargetFramework=net8.0-windows10.0.20348.0]
@rmarinho, I have modified changes for this issue. Could you please validate it once and let me know if there are any further concerns. |
Can we also rebase on main? we made some changes on the pipeline agents and we need the pr to pick them up. Thanks |
/rebase |
@PureWeen, I have updated test image for this issue. Could you please validate it once and let me know if there are any further concerns. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just please address LINQ comment
@Foda, I have updated the code based on your suggestion. Could you please review it and let me know if you have any further concerns. |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Root cause
WinUI AutoSuggestbox does not have MaxLength property in native, SearchBar.MaxLength is not updated to native property.
Description of Issue Fix
Modified SearchBar by taking the AutoSuggestbox child, a textbox control in UpdateMaxLength() and updated SearchBar.MaxLength to native textbox.MaxLength.
Tested the behavior in the following platforms.
Issues Fixed
Fixes #5669
Output
5669_BeforeChange.mp4
5669_AfterChange.mp4