我有一个名为ObservableCollection<MyClass>
myCollection
应当绑定两个CollectionViewSource
S(AllItems
SelectedItems
和)。绑定的ObservableCollection作为源不同CollectionViewSource
AllItems
的源属性绑定到myCollection
。 SelectedItems
的来源物业应绑定到myCollection
项目,其中IsSelected == true
。
public class MyClass : INotifyPropertyChanged
{
//fields and interface implementations
public string Name {//proper code};
public bool? IsSelected {//proper code};
}
// some where else in the MainWindow
AllItems.Source = myCollection;
SelectedItems.Source = myCollection.Where(input=>input.IsSelected==true);
问题:加载窗口时每一件事情是确定。但是当myCollection
中某些项目的IsSelected
值明显变化时,它对SelectedItems
没有影响。所以为了克服这个问题,我每次更新IsSelected
属性时都会更新SelectedItems
的源属性。
问题:我该如何做这些绑定,以便不需要手动更新SelectedItems
的源属性?
Thnaks。
通过'正确的代码'我的意思是我知道我应该提高它。 – 2013-04-02 12:59:51
@HosseinNarimaniRad - 比你应该尝试我的建议与调试模式 – MikroDel 2013-04-02 13:01:12
答案是这样的:有没有办法使自动更新,我必须在正确的地方让一些刷新。 – 2013-04-02 13:03:23