Data Binding and the AutoCompleteBox.Text Property
Populating the Text
property of the AutoCompleteBox
via a data binding can be problematic, since when a suggestion is chosen the binding is effectively removed and therefore needs to be restored.
You can reapply a binding by subscribing to the SelectionChanged
event of the AutoCompleteBox
.
void AutoCompleteBox_SelectionChanged( object sender, SelectionChangedEventArgs e){ AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; Dispatcher.BeginInvoke(delegate { Binding binding = new Binding("YourViewModelTextProperty"); binding.Source = autoCompleteBox.DataContext; autoCompleteBox.SetBinding(AutoCompleteBox.TextProperty, ...
Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.