我想在每次选择另一个ListCollectionView的项目时更新列表框中的ListCollection。
我有两个ListViewCollection,SceneCollectionView和ShotCollectionView。我希望根据ShotCollectionView中的属性SceneNumber过滤SceneCollection,但在SceneCollectionView中,当我从一个项目转到另一个项目时,我可以获得要更新的ShotCollectionView。
这是我的ViewModel
public class ShotListViewModel : NotifyUIBase
{
public ListCollectionView SceneCollectionView { get; set; }
private Scenes CurrentScene
{
get { return SceneCollectionView.CurrentItem as Scenes; }
set { SceneCollectionView.MoveCurrentTo(value); RaisePropertyChanged(); }
}
private ObservableCollection<Shot> _allShots = new ObservableCollection<Shot>();
public ObservableCollection<Shot> AllShots
{
get { return _allShots; }
set { _allShots = value; RaisePropertyChanged();}
}
private ListCollectionView _allShotsCollection;
public ListCollectionView AllShotsCollection
{
get
{
if (_allShotsCollection == null)
{
_allShotsCollection = new ListCollectionView(this.AllShots);
_allShotsCollection.Filter = IsSceneNumber;
}
return _allShotsCollection;
}
}
private bool IsSceneNumber(object obj)
{
if (obj as Shot != null
&& (obj as Shot).SceneNumber == (SceneCollectionView.CurrentItem as Scene).SceneNumber)
{
return true;
}
return false;
}
public ShotListViewModel()
{
SceneCollectionView = Application.Current.Resources["SceneCollectionView"] as ListCollectionView;
GetShotList(); //Populates the AllShots Observable collection.
AddShotCommand = new RelayCommand(AddShot);
FilterShotsCommand = new RelayCommand(AddShot);
}为了让它工作,我在这里遗漏了什么,还是使用ICollectionViewLiveShaping更好。但是我不知道如何实现它
发布于 2015-06-26 19:35:44
我不明白你想做什么,但让我们举一个例子:
让我们假设我们有
绑定到ListBox1Items的ListBox1和绑定到的ListBox2
如果要过滤ListBox2中的数据,则必须过滤ListBox2Items.如何做到这一点?很简单:您可以绑定到-假设- ListBox1SelectedItem. - ListBox1有一个属性SelectedItem每次选择更改时,在ListBox1SelectedItem的设置器中,您都可以在ListBox2Items.上触发一个过滤器
希望你能理解我所解释的。
https://stackoverflow.com/questions/31069051
复制相似问题