views:

18

answers:

0

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?