Observable Lists, Interfaces, Lists and sorting, oh my...
-
I'm trying to come up with a non-WTF version here but, well.
Here's the gist:
I want to display two classes (
Reminder
andUpcomingDate
) in one GridView. They also should be sorted by theirDateTime StartDate
property.So I created an Interface (let's call it
IDate
) and made the two classes use that interface. Also created anObservableCollection<IDate>
. The instances for the classes are pulled like this:List<Reminder> reminders = await _reminderTable .CreateQuery() .ToListAsync();
I could also do a
ToCollectionAsync()
. Now, here's the thing:Collections<>
have noSort()
function.Lists<>
do, however.So, how do I put the whole sorted shebang into the
ObservableCollection<IDate>
without resorting to severalforeach
?
-
I haven't touched C# for a while but I think you can pass the sorted list to the ObservableCollection's constructor.
-
The only idea I'm capable of at this time (it's 01:41 AM CEST here) is deriving ObservableList<T> from LIst<T>, INotifyCollectionChanged, and INotifyPropertyChanged.
-
There's no
Sort()
, but can't you stick anOrderBy()
in there? Mind that AFAIR it's not in-place, though.
-
This is correct. Observable collection is very much a list, and it's constructor won't reorder what you pass in.
-
I haven't touched C# for a while but I think you can pass the sorted list to the ObservableCollection's constructor.
Well, that got rid of one
foreach
. Should've thought of that myself.As for the rest - oh well, it's not as if this routine was particularly time sensitive
-
As I recall, there's a class called something like IOrderedEnumerable.
Or you could sort on display using LINQ.
Edit: NM - none of my suggestions apply .... I am TR :WTF:
-
-
<dot tv> WolskSellout WolskSellout