Im tinkering with XAML C# for the first time, playing with some existing data. I need to sort by CollectionView and im getting abit lost.
I want to sort on the HighScores page by Score
That code belongs in your ViewModel, which is conveniently the only file you neglected to post. Also, please post your code as text, not screenshots, in the future.
Thanks Sorry, and noted. ViewModel attached.
So LINQ has a pretty convenient OrderByDescending method, which I would just drop into your loading command:
var items = await DataStore.GetItemsAsync(true);
var sortedItems = items.OrderByDescending(i => i.Score);
foreach (var item in sortedItems)
Thanks, that didnt seem to work for sorting Score, but if I was to sort by name that did. Is that due to Score being a string not an int?
I cant change score to an int as that causes more problems.
Is there a way of sorting strings which are numbers?
I'm concerned about what type of problems Score being an int would cause you.
You could create an implementation of IComparer that parses Score into a number for sorting purposes. This documentation has an example.
We could parse it to double like:
var sortedItems = items.OrderBy(i => double.Parse(i.Score)).ToList();
If all the score are valid double strings.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies