【问题标题】:Silverlight 4 AutoCompleteBox, setting SelectedItem to nullSilverlight 4 AutoCompleteBox,将 SelectedItem 设置为 null
【发布时间】:2010-10-22 08:33:03
【问题描述】:

在 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 而不是空字符串。有人可以解释为什么这样写,并提出解决方法吗?

【问题讨论】:

  • 感谢您为我指明正确的方向。

标签: silverlight-4.0 autocompletebox


【解决方案1】:

我相信是这样,当没有实际的搜索项时,该框会显示类似“在此处搜索”的内容。例如,查看 StackOverflow 的搜索框,当它为空时显示“搜索”。

【讨论】:

    【解决方案2】:

    这真的很烦人,我还没有找到解决办法。它位于 Silverlight Toolkit 问题跟踪器 here。我还阅读了 here 一些关于将 ItemsSource 设置为 null 的内容。

    如果我找到解决方法,我会更新。

    【讨论】:

      猜你喜欢
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      相关资源
      最近更新 更多