First, I want to say that after several study on 2 different threads (shown below), I decided to post this question since it's quite different.
So, I want to bind an ItemsControl
from my view to a property to get a reversed version of a collection.
I have this view (trimmed for clarity) :
<UserControl x:Class="NumberedMusicalScoresWriter.V.NotationGroupV" ...>
...
<Grid>
<ItemsControl ...
ItemsSource="{Binding ReversedNotationVMs, Mode=OneWay}">
...
</ItemsControl>
</Grid>
...
</UserControl>
And, I have this viewmodel (trimmed for clarity) :
public class NotationGroupVM : ...
{
...
public ObservableCollection<NotationVM> ReversedNotationVMs
{
get { return (ObservableCollection<NotationVM>)NotationVMs.Reverse(); //ERROR!! }
}
public ObservableCollection<NotationVM> NotationVMs
{
get { return _notationVMs; }
set { _notationVMs = value; NotifyPropertyChanged("NotationVMs"); NotifyPropertyChanged("ReversedNotationVMs"); }
}
}
But there's this error (See error comment above to spot the problematic line) :
Unable to cast object of type 'd__a0
1[NumberedMusicalScoresWriter.VM.NotationVM]' to type 'System.Collections.ObjectModel.ObservableCollection
1[NumberedMusicalScoresWriter.VM.NotationVM]'.
I've also tried to apply .ToList<NotationVM>()
before reversing, and making a new collection each time the main field got updated. But they didn't work out.
I also need to keep the reversed to be sync-ed with the un-reversed one. NOT just one time reversion only
I've also read an issue about it here and here, but all of them provide either the xaml solution only or i didn't understand them. I need the VM one.
Thanks.