@@ -101,31 +101,36 @@ private void OnApplyTemplateAutoSuggestBox(AutoSuggestBox auto)
101
101
_autoSuggestBox . LostFocus += AutoSuggestBox_LostFocus ;
102
102
103
103
// Setup a binding to the QueryIcon of the Parent if we're the last box.
104
- if ( Content is ITokenStringContainer str && str . IsLast )
104
+ if ( Content is ITokenStringContainer str )
105
105
{
106
- // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2568
107
- if ( Owner . QueryIcon is FontIconSource fis &&
108
- fis . ReadLocalValue ( FontIconSource . FontSizeProperty ) == DependencyProperty . UnsetValue )
109
- {
110
- // This can be expensive, could we optimize?
111
- // Also, this is changing the FontSize on the IconSource (which could be shared?)
112
- fis . FontSize = Owner . TryFindResource ( "TokenizingTextBoxIconFontSize" ) as double ? ?? 16 ;
113
- }
106
+ // We need to set our initial text in all cases.
107
+ _autoSuggestBox . Text = str . Text ;
114
108
115
- var iconBinding = new Binding ( )
109
+ // We only set/bind some properties on the last textbox to mimic the autosuggestbox look
110
+ if ( str . IsLast )
116
111
{
117
- Source = Owner ,
118
- Path = new PropertyPath ( nameof ( Owner . QueryIcon ) ) ,
119
- RelativeSource = new RelativeSource ( ) { Mode = RelativeSourceMode . TemplatedParent }
120
- } ;
112
+ // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2568
113
+ if ( Owner . QueryIcon is FontIconSource fis &&
114
+ fis . ReadLocalValue ( FontIconSource . FontSizeProperty ) == DependencyProperty . UnsetValue )
115
+ {
116
+ // This can be expensive, could we optimize?
117
+ // Also, this is changing the FontSize on the IconSource (which could be shared?)
118
+ fis . FontSize = Owner . TryFindResource ( "TokenizingTextBoxIconFontSize" ) as double ? ?? 16 ;
119
+ }
121
120
122
- var iconSourceElement = new IconSourceElement ( ) ;
121
+ var iconBinding = new Binding ( )
122
+ {
123
+ Source = Owner ,
124
+ Path = new PropertyPath ( nameof ( Owner . QueryIcon ) ) ,
125
+ RelativeSource = new RelativeSource ( ) { Mode = RelativeSourceMode . TemplatedParent }
126
+ } ;
123
127
124
- iconSourceElement . SetBinding ( IconSourceElement . IconSourceProperty , iconBinding ) ;
128
+ var iconSourceElement = new IconSourceElement ( ) ;
125
129
126
- _autoSuggestBox . QueryIcon = iconSourceElement ;
130
+ iconSourceElement . SetBinding ( IconSourceElement . IconSourceProperty , iconBinding ) ;
127
131
128
- _autoSuggestBox . Text = str . Text ;
132
+ _autoSuggestBox . QueryIcon = iconSourceElement ;
133
+ }
129
134
}
130
135
}
131
136
}
@@ -184,19 +189,11 @@ void WaitForLoad(object s, RoutedEventArgs eargs)
184
189
185
190
private void AutoSuggestBox_TextChanged ( AutoSuggestBox sender , AutoSuggestBoxTextChangedEventArgs args )
186
191
{
187
- var hasDelimiter = ! string . IsNullOrEmpty ( Owner . TokenDelimiter ) && sender . Text ? . Contains ( Owner . TokenDelimiter ) == true ;
188
-
189
- // Ignore in the case we've been set from the parent and already equal the owning text,
190
- // unless we contain our delimiter.
191
- if ( ! hasDelimiter && EqualityComparer < string > . Default . Equals ( sender . Text , Owner . Text ) )
192
+ if ( ! EqualityComparer < string > . Default . Equals ( sender . Text , Owner . Text ) )
192
193
{
193
- return ;
194
+ Owner . Text = sender . Text ; // Update parent text property, if different
194
195
}
195
196
196
- var t = sender . Text . Trim ( ) ;
197
-
198
- Owner . Text = sender . Text ; // Update parent text property
199
-
200
197
// Override our programmatic manipulation as we're redirecting input for the user
201
198
if ( UseCharacterAsUser )
202
199
{
@@ -207,8 +204,10 @@ private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTex
207
204
208
205
Owner . RaiseTextChanged ( sender , args ) ;
209
206
207
+ var t = sender . Text ? . Trim ( ) ?? string . Empty ;
208
+
210
209
// Look for Token Delimiters to create new tokens when text changes.
211
- if ( hasDelimiter )
210
+ if ( ! string . IsNullOrEmpty ( Owner . TokenDelimiter ) && t . Contains ( Owner . TokenDelimiter ) )
212
211
{
213
212
bool lastDelimited = t [ t . Length - 1 ] == Owner . TokenDelimiter [ 0 ] ;
214
213
0 commit comments