@@ -7,7 +7,7 @@ namespace Microsoft.Maui.Platform
77{
88 public static class SearchBarExtensions
99 {
10- private static readonly string [ ] _backgroundColorKeys =
10+ static readonly string [ ] _backgroundColorKeys =
1111 {
1212 "TextControlBackground" ,
1313 "TextControlBackgroundPointerOver" ,
@@ -17,7 +17,7 @@ public static class SearchBarExtensions
1717
1818 public static void UpdateBackground ( this AutoSuggestBox platformControl , ISearchBar searchBar )
1919 {
20- UpdateColors ( platformControl . Resources , _backgroundColorKeys , searchBar . Background ? . ToPlatform ( ) ) ;
20+ UpdateColors ( platformControl , platformControl . Resources , _backgroundColorKeys , searchBar . Background ? . ToPlatform ( ) ) ;
2121 }
2222
2323 public static void UpdateIsEnabled ( this AutoSuggestBox platformControl , ISearchBar searchBar )
@@ -35,7 +35,7 @@ public static void UpdatePlaceholder(this AutoSuggestBox platformControl, ISearc
3535 platformControl . PlaceholderText = searchBar . Placeholder ?? string . Empty ;
3636 }
3737
38- private static readonly string [ ] _placeholderForegroundColorKeys =
38+ static readonly string [ ] _placeholderForegroundColorKeys =
3939 {
4040 "TextControlPlaceholderForeground" ,
4141 "TextControlPlaceholderForegroundPointerOver" ,
@@ -45,7 +45,7 @@ public static void UpdatePlaceholder(this AutoSuggestBox platformControl, ISearc
4545
4646 public static void UpdatePlaceholderColor ( this AutoSuggestBox platformControl , ISearchBar searchBar )
4747 {
48- UpdateColors ( platformControl . Resources , _placeholderForegroundColorKeys ,
48+ UpdateColors ( platformControl , platformControl . Resources , _placeholderForegroundColorKeys ,
4949 searchBar . PlaceholderColor ? . ToPlatform ( ) ) ;
5050 }
5151
@@ -54,7 +54,7 @@ public static void UpdateText(this AutoSuggestBox platformControl, ISearchBar se
5454 platformControl . Text = searchBar . Text ;
5555 }
5656
57- private static readonly string [ ] _foregroundColorKeys =
57+ static readonly string [ ] _foregroundColorKeys =
5858 {
5959 "TextControlForeground" ,
6060 "TextControlForegroundPointerOver" ,
@@ -66,7 +66,7 @@ public static void UpdateTextColor(this AutoSuggestBox platformControl, ISearchB
6666 {
6767 var tintBrush = searchBar . TextColor ? . ToPlatform ( ) ;
6868
69- if ( tintBrush == null )
69+ if ( tintBrush is null )
7070 {
7171 platformControl . Resources . RemoveKeys ( _foregroundColorKeys ) ;
7272 platformControl . Foreground = null ;
@@ -80,7 +80,7 @@ public static void UpdateTextColor(this AutoSuggestBox platformControl, ISearchB
8080 platformControl . RefreshThemeResources ( ) ;
8181 }
8282
83- private static void UpdateColors ( ResourceDictionary resource , string [ ] keys , Brush ? brush )
83+ private static void UpdateColors ( AutoSuggestBox platformControl , ResourceDictionary resource , string [ ] keys , Brush ? brush )
8484 {
8585 if ( brush is null )
8686 {
@@ -90,6 +90,8 @@ private static void UpdateColors(ResourceDictionary resource, string[] keys, Bru
9090 {
9191 resource . SetValueForAllKey ( keys , brush ) ;
9292 }
93+
94+ platformControl . RefreshThemeResources ( ) ;
9395 }
9496
9597 public static void UpdateFont ( this AutoSuggestBox platformControl , ISearchBar searchBar , IFontManager fontManager ) =>
@@ -126,14 +128,20 @@ public static void UpdateMaxLength(this AutoSuggestBox platformControl, ISearchB
126128 }
127129
128130 if ( maxLength == 0 )
131+ {
129132 MauiAutoSuggestBox . SetIsReadOnly ( platformControl , true ) ;
133+ }
130134 else
135+ {
131136 MauiAutoSuggestBox . SetIsReadOnly ( platformControl , searchBar . IsReadOnly ) ;
137+ }
132138
133139 var currentControlText = platformControl . Text ;
134140
135141 if ( currentControlText . Length > maxLength )
142+ {
136143 platformControl . Text = currentControlText . Substring ( 0 , maxLength ) ;
144+ }
137145 }
138146
139147 public static void UpdateIsReadOnly ( this AutoSuggestBox platformControl , ISearchBar searchBar )
@@ -146,7 +154,9 @@ public static void UpdateIsTextPredictionEnabled(this AutoSuggestBox platformCon
146154 var textBox = platformControl . GetFirstDescendant < TextBox > ( ) ;
147155
148156 if ( textBox is null )
157+ {
149158 return ;
159+ }
150160
151161 textBox . UpdateIsTextPredictionEnabled ( searchBar ) ;
152162 }
@@ -156,7 +166,9 @@ public static void UpdateIsSpellCheckEnabled(this AutoSuggestBox platformControl
156166 var textBox = platformControl . GetFirstDescendant < TextBox > ( ) ;
157167
158168 if ( textBox is null )
169+ {
159170 return ;
171+ }
160172
161173 textBox . UpdateIsSpellCheckEnabled ( searchBar ) ;
162174 }
@@ -165,13 +177,15 @@ public static void UpdateKeyboard(this AutoSuggestBox platformControl, ISearchBa
165177 {
166178 var queryTextBox = platformControl . GetFirstDescendant < TextBox > ( ) ;
167179
168- if ( queryTextBox == null )
180+ if ( queryTextBox is null )
181+ {
169182 return ;
183+ }
170184
171185 queryTextBox . UpdateInputScope ( searchBar ) ;
172186 }
173187
174- private static readonly string [ ] CancelButtonColorKeys =
188+ static readonly string [ ] CancelButtonColorKeys =
175189 {
176190 "TextControlButtonForeground" ,
177191 "TextControlButtonForegroundPointerOver" ,
@@ -183,7 +197,9 @@ internal static void UpdateCancelButtonColor(this AutoSuggestBox platformControl
183197 var cancelButton = platformControl . GetDescendantByName < Button > ( "DeleteButton" ) ;
184198
185199 if ( cancelButton is null )
200+ {
186201 return ;
202+ }
187203
188204 cancelButton . UpdateTextColor ( searchBar . CancelButtonColor , CancelButtonColorKeys ) ;
189205 }
0 commit comments