22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5+ using System . Collections . Generic ;
56using Windows . Foundation ;
67using Windows . System ;
78using Windows . UI ;
@@ -123,6 +124,8 @@ private void OnApplyTemplateAutoSuggestBox(AutoSuggestBox auto)
123124 iconSourceElement . SetBinding ( IconSourceElement . IconSourceProperty , iconBinding ) ;
124125
125126 _autoSuggestBox . QueryIcon = iconSourceElement ;
127+
128+ _autoSuggestBox . Text = str . Text ;
126129 }
127130 }
128131 }
@@ -156,8 +159,40 @@ private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestB
156159 Owner . RaiseSuggestionChosen ( sender , args ) ;
157160 }
158161
162+ // Called to update text by link:TokenizingTextBox.Properties.cs:TextPropertyChanged
163+ internal void UpdateText ( string text )
164+ {
165+ if ( _autoSuggestBox != null )
166+ {
167+ _autoSuggestBox . Text = text ;
168+ }
169+ else
170+ {
171+ void WaitForLoad ( object s , RoutedEventArgs eargs )
172+ {
173+ if ( _autoSuggestTextBox != null )
174+ {
175+ _autoSuggestTextBox . Text = text ;
176+ }
177+
178+ AutoSuggestTextBoxLoaded -= WaitForLoad ;
179+ }
180+
181+ AutoSuggestTextBoxLoaded += WaitForLoad ;
182+ }
183+ }
184+
159185 private void AutoSuggestBox_TextChanged ( AutoSuggestBox sender , AutoSuggestBoxTextChangedEventArgs args )
160186 {
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+ {
193+ return ;
194+ }
195+
161196 var t = sender . Text . Trim ( ) ;
162197
163198 Owner . Text = sender . Text ; // Update parent text property
@@ -173,7 +208,7 @@ private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTex
173208 Owner . RaiseTextChanged ( sender , args ) ;
174209
175210 // Look for Token Delimiters to create new tokens when text changes.
176- if ( ! string . IsNullOrEmpty ( Owner . TokenDelimiter ) && t . Contains ( Owner . TokenDelimiter ) )
211+ if ( hasDelimiter )
177212 {
178213 bool lastDelimited = t [ t . Length - 1 ] == Owner . TokenDelimiter [ 0 ] ;
179214
0 commit comments