silverlight-4.0 – Silverlight 4 AutoCompleteBox,将SelectedItem设置为null

在AutoCompleteBox的源代码中(可从Microsoft下载),我发现了以下内容:

/// <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;
  }
}

困扰我的是{text = SearchText;}行.如果我将SelectedItem绑定到我的ViewModel并且在搜索条目进入AutoCompleteBox之后,SearchText不为空,那么当底层数据重置为null时,AutoCompleteBox可能会显示SearchText而不是空字符串.有人可以解释为什么这样写,并建议一个解决方法?

解决方法

我相信这样,当没有实际的搜索项时,该框会显示“搜索此处”之类的内容.有关示例,请参阅StackOverflow的搜索框,其中显示“搜索”为空.

相关文章

如何在Silverlight4(XAML)中绑定IsEnabled属性?我试过简单的...
我正在编写我的第一个vb.net应用程序(但我也会在这里标记c#,...
ProcessFile()是在UIThread上运行还是在单独的线程上运行.如...
我从同行那里听说,对sharepoint的了解对职业生涯有益.我们不...
我正在尝试保存一个类我的类对象的集合.我收到一个错误说明:...
我需要根据Silverlight中的某些配置值设置给定控件的Style.我...