Silverlight 4 AutoCompleteBox by setting SelectedItem to null

In the AutoCompleteBox source code (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 bothers me is the line {text = SearchText;}. If I associate the SelectedItem with my ViewModel and after writing the search to the AutoCompleteBox, the SearchText is not empty, then when the underlying reset data is null, the AutoCompleteBox can display the SearchText instead of an empty string. Can someone explain why this is written this way and suggest a workaround?

+5
source share
2 answers

, , , - " ". , . StackOverflow, "", .

+1

, . . - ItemsSource null, .

, .

+1

All Articles