Silverlight 4.0 Silverlight 4自动完成框,将SelectedItem设置为空
在AutoCompleteBox(可从Microsoft下载)的源代码中,我发现了以下内容:Silverlight 4.0 Silverlight 4自动完成框,将SelectedItem设置为空,silverlight-4.0,autocompletebox,Silverlight 4.0,Autocompletebox,在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.<
/// <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;
}
}
//
///更改选定项时调用,更新文本值
///显示在文本框部件中的。
///
///新项目。
SelectedItemChanged上的私有无效(对象newItem)
{
字符串文本;
if(newItem==null)
{
文本=搜索文本;
}
其他的
{
text=格式值(newItem,true);
}
//更新文本属性和文本框值
UpdateTextValue(文本);
//将插入符号移动到文本框的末尾
if(TextBox!=null&&Text!=null)
{
TextBox.SelectionStart=Text.Length;
}
}
困扰我的是{text=SearchText;}行。如果将SelectedItem绑定到我的ViewModel,并且在自动完成框中输入搜索条目后,SearchText不为空,则当基础数据重置为null时,自动完成框可能会显示SearchText而不是空字符串。有人能解释为什么这样写,并提出解决办法吗 我相信这是因为当没有实际的搜索项目时,框中会显示类似“search Here”的内容。例如,请参阅StackOverflow的搜索框,该框为空时会显示“搜索”。这真的很烦人,我还没有找到解决方法。它位于Silverlight Toolkit问题跟踪程序上。我还阅读了一些关于将ItemsSource设置为null的内容,我将使用这些内容
如果找到解决方法,我会更新。谢谢你为我指明了正确的方向。