筛选DataGrid WPF

时间:2018-12-24 07:17:05

标签: c# wpf collectionviewsource

我试图过滤DataGrid。但是viewSource.View.Refresh()没有被调用。

为什么?

尽管打印了文本ComboBox_SelectionChanged

private CollectionViewSource viewSource;
public ObservableCollection<Event> Events = new ObservableCollection<Event>();
public ReportWindow()
{
    InitializeComponent();            
    Task t = GetEventsFromDBAsync(FromDate, ToDate);
    t.Wait();

    viewSource = new CollectionViewSource
    {
        Source = Events
    };

    viewSource.Filter += new FilterEventHandler(ViewSource_Filter);
    ICollectionView Itemlist = viewSource.View;
    EventsDataGrid.ItemsSource = Itemlist;  
}

void ViewSource_Filter(object sender, FilterEventArgs e)
{
    Console.WriteLine("filter");
}
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs e)
{
    viewSource.View.Refresh();
    Console.WriteLine("ComboBox_SelectionChanged");
}

0 个答案:

没有答案