Trong mã nguồn của AutoCompleteBox (tải về từ Microsoft) Tôi thấy như sau:Silverlight 4 AutoCompleteBox, thiết SelectedItem null
/// <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;
}
}
gì phiền tôi là {text = searchText;} dòng. Nếu tôi liên kết SelectedItem với ViewModel của tôi và sau khi một mục nhập tìm kiếm vào AutoCompleteBox, SearchText không rỗng, sau đó khi dữ liệu cơ bản được đặt lại thành null, AutoCompleteBox có thể hiển thị SearchText thay vì chuỗi rỗng. Ai đó có thể giải thích lý do tại sao nó được viết theo cách này, và đề nghị một workaround?
Cảm ơn bạn đã chỉ cho tôi đúng hướng. –