使用MVVM清除列表框的选定项(绑定到对象集合)

时间:2011-01-11 01:40:37

标签: silverlight binding

我有一个带有silverlight 4的列表框。我将列表绑定到对象列表。

1。)SelectedValue属性绑定到名为Current的viewmodel的公共属性。我该如何清除选择?我试过将Current的值设置为null。好吧,这会清除选择,但是它也会破坏编辑形式中的绑定,该形式具有绑定到'Current'属性的组合框。绑定到Current.FirstName等的文本框正常工作,但在将Current对象设置为null后组合框不起作用。

2.。)如何在没有选择第一个项目的情况下加载表单?

3 个答案:

答案 0 :(得分:0)

在Silverlight中找到解决此错误的方法:

// Bug in SL listbox prevents SelectedIndex = -1 from unselected.
// Workaround is to use DispatcherBeginInvoke to do it async. Found
// work around here:
// http://sharplogic.com/blogs/rdavis/PermaLink,guid,2f5bbfa1-4878-490f-967d-bf00bc04dfde.aspx
Dispatcher.BeginInvoke(() => { QuickItemsListBox.SelectedIndex = -1; });

此处有更多详情: http://sharplogic.com/blogs/rdavis/PermaLink,guid,2f5bbfa1-4878-490f-967d-bf00bc04dfde.aspx

答案 1 :(得分:0)

不知道什么时候修复了,但是VoodooChild的答案现在可以在Silverlight 5中使用了。传递它以防其他人正在寻找。

yourCB.selectedIndex = -1;

答案 2 :(得分:-1)

尝试:

yourCB.SelectedIndex = -1;

相关问题