WPF CollectionViewSource.View null



我从一个触发器中获得了CollectionViewSource筛选,但在获得第二个筛选器时遇到了问题。问题来自于一个视图(MainWindow.xaml(中的按钮必须是PosterView中CollectionViewSource的触发器。

PosterView.xaml

<CollectionViewSource x:Key="GameListCVS"
Source="{Binding PosterViewOC}"
CollectionViewType="{x:Type dat:ListCollectionView}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Title" />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>

PosterView.xaml.cs

private void SearchString_TextChanged(object sender, TextChangedEventArgs e)
{
RefreshList();
}
public void RefreshList() 
{
GameListCV = ((CollectionViewSource)(FindResource("GameListCVS")));
GameListCV.Filter += new FilterEventHandler(GenreFilter);
GameListCV.Filter += new FilterEventHandler(GameSearch);
if (GameListCV.View != null) //This is getting a null "GameListCV.View" on genre only, works if searchbar updated
GameListCV.View.Refresh();
}

主窗口.xaml.cs

private void ApplyGenreFilter_OnClick(object sender, RoutedEventArgs e)
{ 
string genreToFilter = ((Button)sender).Tag.ToString();
pv.GenreToFilter(genreToFilter);//passes the button tag and runs RefreshList();
MenuToggleButton.IsChecked = false; //hide hamburger
}

RefreshList((似乎只有在搜索栏中输入文本时才能获得CVS的视图。我尝试在PosterView中添加一个按钮来刷新GenreFilter,效果很好,所以这意味着问题来自于主窗口中有一个按钮,然后调用PosterView.RefreshList((;-它无法找到资源("GameListCVS"(

有没有解决方法(明确地对FindResource说"在PosterView中查找GameListCVS"(-因为目前用户必须在TextBox中搜索,删除它,然后他们可以过滤流派精细

我认为你必须从ListCollectionView派生,在构造函数中,你可以在那里设置CustomSort属性

最新更新