В исходном коде 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 не будет пустым, тогда, когда базовые данные сбрасываются в ноль, AutoCompleteBox может отображать SearchText вместо пустой строки. Может кто-нибудь объяснить, почему это так написано, и предложить обходной путь?