In the source code of AutoCompleteBox (downloadable from Microsoft) I found the following:
/// <summary>
/// Called when the selected item is changed, updates the text value
/// that is displayed in the text box part.
/// </summary>
/// <param name="newItem">The new item.</param>
private void OnSelectedItemChanged(object newItem)
{
string text;
if (newItem == null)
{
text = SearchText;
}
else
{
text = FormatValue(newItem, true);
}
// Update the Text property and the TextBox values
UpdateTextValue(text);
// Move the caret to the end of the text box
if (TextBox != null && Text != null)
{
TextBox.SelectionStart = Text.Length;
}
}
What troubles me is {text = SearchText;} line. If I bind SelectedItem to my ViewModel and after a search entry into the AutoCompleteBox, SearchText is not empty, then when underlying data is reset to null, AutoCompleteBox may display SearchText instead of empty string. Can someone explain why it is written this way, and suggest a workaround?
This is really annoying and I've yet to find a fix. It is on the Silverlight Toolkit issue tracker here. I've also read something here about setting the ItemsSource to null that I'm going to play about with.
I'll update if I find a workaround.
I believe that's so that when there is no actual search item, the box displays something like "Search Here". For an example, see StackOverflow's search box, which says "search" when it is empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With