I have two viewmodels with an observablecollection in each viewmodel.
These collection have an relation to each other.
For instance let say one is a collection of ClassA that have an Id and a Name the other is a collection of ClassB that has an ClassAId and some OtherValue
Is it possible to databind these to a ListView so that for each item in CollectionA the OtherValue is fetched from CollectionB
<ListView ItemsSource="{Binding ViewModelA.CollectionClassA}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=ClassA.Name}"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=ClassB.OtherValue}"/>
</GridView>
</ListView.View>
</ListView>
I hope I didn’t confuse you to much with my explanation of my question:)
You’re best option is to return a new collection that is formed at the view-model level based upon a new view-model (or model) that is special to that collection:
XAML:
Caveats:
ObservableCollection<T>or not, it’s up to you if you need this collection to be observable.ClassAandClassBcollections so that it can update your main collection when they either of them change.Either way, this should give you a good idea of the direction to go in, with some minor adjustments to fit into your code.