Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多个可刷新集合单个可观察集合的ViewSources_C#_Wpf - Fatal编程技术网

C# 多个可刷新集合单个可观察集合的ViewSources

C# 多个可刷新集合单个可观察集合的ViewSources,c#,wpf,C#,Wpf,有没有什么方法可以让我在一个可观察的集合上拥有多个视图,并使用不同的过滤器进行刷新 我有一个可观察的集合叫做熟练度。我有三个列表框,每个列表框应该显示Proficiencies项的子集,根据Proficiencies项中的值进行过滤。i、 e.一个列表显示A类项目,一个列表显示B类项目,一个列表显示C类项目 我正在尝试使用CollectionViewSources(称为SkillsView、ToolsView和LanguagesView,每个列表框一个,每个列表框都有自己的筛选器)筛选集合。它们

有没有什么方法可以让我在一个可观察的集合上拥有多个视图,并使用不同的过滤器进行刷新

我有一个可观察的集合叫做熟练度。我有三个列表框,每个列表框应该显示Proficiencies项的子集,根据Proficiencies项中的值进行过滤。i、 e.一个列表显示A类项目,一个列表显示B类项目,一个列表显示C类项目

我正在尝试使用CollectionViewSources(称为SkillsView、ToolsView和LanguagesView,每个列表框一个,每个列表框都有自己的筛选器)筛选集合。它们是列表框绑定到的ViewModel类中的属性。它们以以下形式声明:

    protected ICollectionView theSkillsView;

    public ICollectionView SkillsView
    {
        get { return theSkillsView; }
        protected set
        {
            theSkillsView = value;
            OnPropertyChanged("SkillsView");
        }
    }
我有两种初始化它们的方法(1):

或我发现的替代方案(2):

然后,我应用过滤:

        theLanguagesView.Filter = p => ((ProficiencyData) p).Category == ProficiencyCategoryType.Language;
        theSkillsView.Filter = p => ((ProficiencyData) p).Category == ProficiencyCategoryType.Skill;
        theToolsView.Filter = p => ((ProficiencyData) p).Category == ProficiencyCategoryType.Tool;
问题是: 如果使用选项(1),所有视图都具有相同的过滤器(最后应用的过滤器) 如果在调用Refresh()时使用选项(2),则会出现以下错误:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=PresentationFramework
  StackTrace:
   at System.Windows.Data.ListCollectionView.PrepareLocalArray()
我可以创建三个独立的集合,但是a)这意味着我没有在一个集合中拥有所有的项目,b)当CollectionViewSources可以精确地进行排序、分组和筛选时,这似乎不符合实际情况


非常感谢您的建议。

您应该创建
AllItemsInDataBase
源代码集合的三个独立视图:

theSkillsView = new ListCollectionView(AllItemsInDataBase);
theToolsView  = new ListCollectionView(AllItemsInDataBase);
theLanguagesView = new ListCollectionView(AllItemsInDataBase);
然后可以独立地过滤视图

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=PresentationFramework
  StackTrace:
   at System.Windows.Data.ListCollectionView.PrepareLocalArray()
theSkillsView = new ListCollectionView(AllItemsInDataBase);
theToolsView  = new ListCollectionView(AllItemsInDataBase);
theLanguagesView = new ListCollectionView(AllItemsInDataBase);