@@ -101,31 +101,36 @@ private void OnApplyTemplateAutoSuggestBox(AutoSuggestBox auto)
101101                _autoSuggestBox . LostFocus  +=  AutoSuggestBox_LostFocus ; 
102102
103103                // 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 ) 
105105                { 
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 ; 
114108
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 ) 
116111                    { 
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+                         } 
121120
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+                         } ; 
123127
124-                     iconSourceElement . SetBinding ( IconSourceElement . IconSourceProperty ,   iconBinding ) ; 
128+                          var   iconSourceElement   =   new   IconSourceElement ( ) ; 
125129
126-                     _autoSuggestBox . QueryIcon   =   iconSourceElement ; 
130+                          iconSourceElement . SetBinding ( IconSourceElement . IconSourceProperty ,   iconBinding ) ; 
127131
128-                     _autoSuggestBox . Text  =  str . Text ; 
132+                         _autoSuggestBox . QueryIcon  =  iconSourceElement ; 
133+                     } 
129134                } 
130135            } 
131136        } 
@@ -184,19 +189,11 @@ void WaitForLoad(object s, RoutedEventArgs eargs)
184189
185190        private  void  AutoSuggestBox_TextChanged ( AutoSuggestBox  sender ,  AutoSuggestBoxTextChangedEventArgs  args ) 
186191        { 
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 ) ) 
192193            { 
193-                 return ; 
194+                 Owner . Text   =   sender . Text ;   // Update parent text property, if different 
194195            } 
195196
196-             var  t  =  sender . Text . Trim ( ) ; 
197- 
198-             Owner . Text  =  sender . Text ;  // Update parent text property 
199- 
200197            // Override our programmatic manipulation as we're redirecting input for the user 
201198            if  ( UseCharacterAsUser ) 
202199            { 
@@ -207,8 +204,10 @@ private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTex
207204
208205            Owner . RaiseTextChanged ( sender ,  args ) ; 
209206
207+             var  t  =  sender . Text ? . Trim ( )  ??  string . Empty ; 
208+ 
210209            // Look for Token Delimiters to create new tokens when text changes. 
211-             if  ( hasDelimiter ) 
210+             if  ( ! string . IsNullOrEmpty ( Owner . TokenDelimiter )   &&   t . Contains ( Owner . TokenDelimiter ) ) 
212211            { 
213212                bool  lastDelimited  =  t [ t . Length  -  1 ]  ==  Owner . TokenDelimiter [ 0 ] ; 
214213
0 commit comments