0

I have an ObservableCollection of Value object called Values. Value object has name, percentage and size properties. Percentages are calculated among all values.

Then, i have a chart control binded to an IcollectionView created from the Values sorted by percentage.

var IValues = (CollectionView)new CollectionViewSource { Source = Dmodel.Values }.View;
Ivalues.SortDescriptions.Add(new SortDescription("Percentage", ListSortDirection.Descending));

I can apply a filter based on name, size, percentage... whatever.

IValues.Filter = o => 
{ 
    Value v = o as Value; 
    return v.Name.Contains(SearchedText); 
}

But, how can i filter the first N values of the IcollectionView? I know how i can do it in the ObservableCollection with a simple:

Values = Values.OrderByDescending(x => x.Percentage).Take(10);

But i prefer to maintain the original data source untouched because i'm using a user control binding the ICollectionView and all the filtering logic is in the control code behind.

Thanks!

Hüsk3rDü
  • 583
  • 1
  • 4
  • 12

1 Answers1

0

Btw...

int count = 0;
int max = 50;
IValues.Filter += o => ++count <= max;

Will filter the first 50 (max) objects in IValues...

Hüsk3rDü
  • 583
  • 1
  • 4
  • 12