2015-06-26 27 views
0

我想每次選擇另一個ListCollection的項目時更新列表框中的ListCollectionView。更新ListcollectionView基於其他ListCollectionView的當前項目

我有2個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。但我不知道如何實現

回答

0

我不`噸明白你試圖這樣做,但讓我們來談談對一個例子:

比方說我們有

ListBox1綁定到ListBox1ItemsListBox2綁定到ListBox2Items

如果要過濾來自ListBox2的數據,您必須過濾ListBox2Items。怎麼做 ?很簡單:ListBox1有一個屬性SelectedItem你可以綁定---可以說--- --- ListBox1SelectedItem。每次選擇更改時,在ListBox1SelectedItem的設置器中,您可以觸發ListBox2Items上的過濾器。

希望你明白我說過的話。

相關問題