Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. // EventsControl class
  2.  
  3. private bool Filter(object obj)
  4. {
  5. if (!(obj is Event @event)) return false;
  6. if (string.IsNullOrEmpty(Location)) return true;
  7.  
  8. return true;
  9. // return @event.Location == Location;
  10. }
  11.  
  12. public static readonly DependencyProperty EventsSourceProperty = DependencyProperty.Register(
  13. nameof(EventsSource), typeof(ObservableCollection<Event>), typeof(EventsControl), new PropertyMetadata(default(ObservableCollection<Event>), EventsSourceChanged));
  14.  
  15. public ObservableCollection<Event> EventsSource
  16. {
  17. get => (ObservableCollection<Event>)GetValue(EventsSourceProperty);
  18. set => SetValue(EventsSourceProperty, value);
  19. }
  20.  
  21. public ICollectionView EventsView { get; set; }
  22.  
  23. private static void EventsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  24. {
  25. if (!(d is EventsControl eventsControl)) return;
  26.  
  27. var view = new CollectionViewSource { Source = e.NewValue }.View;
  28. view.Filter += eventsControl.Filter;
  29. eventsControl.EventsView = view;
  30. //view.Refresh();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement