2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System . Collections . Generic ;
5
6
using Windows . Foundation ;
6
7
using Windows . System ;
7
8
using Windows . UI ;
@@ -123,6 +124,8 @@ private void OnApplyTemplateAutoSuggestBox(AutoSuggestBox auto)
123
124
iconSourceElement . SetBinding ( IconSourceElement . IconSourceProperty , iconBinding ) ;
124
125
125
126
_autoSuggestBox . QueryIcon = iconSourceElement ;
127
+
128
+ _autoSuggestBox . Text = str . Text ;
126
129
}
127
130
}
128
131
}
@@ -156,8 +159,40 @@ private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestB
156
159
Owner . RaiseSuggestionChosen ( sender , args ) ;
157
160
}
158
161
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
+
159
185
private void AutoSuggestBox_TextChanged ( AutoSuggestBox sender , AutoSuggestBoxTextChangedEventArgs args )
160
186
{
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
+
161
196
var t = sender . Text . Trim ( ) ;
162
197
163
198
Owner . Text = sender . Text ; // Update parent text property
@@ -173,7 +208,7 @@ private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTex
173
208
Owner . RaiseTextChanged ( sender , args ) ;
174
209
175
210
// Look for Token Delimiters to create new tokens when text changes.
176
- if ( ! string . IsNullOrEmpty ( Owner . TokenDelimiter ) && t . Contains ( Owner . TokenDelimiter ) )
211
+ if ( hasDelimiter )
177
212
{
178
213
bool lastDelimited = t [ t . Length - 1 ] == Owner . TokenDelimiter [ 0 ] ;
179
214
0 commit comments