I am using Entity Framework and Caliburn.Micro to implement an MVVM application.
Basically, I have set up AuthorModel and BookModel in a one to many relationship - an Author having multiple Books and a Book having only a single Author.
I have a SelectBookWindow where I use DbContext to load ObservableCollection<Book>
, from where I select a Book I want to view/edit. I then pass the selected Book as a parameter to an EditBookWindow where I have a combobox enumerating all the Authors but with the current Author selected.
In here, I load up ObservableCollection<Author>
using a different instance of DbContext and set it as the combobox's ItemsSource
and as well as do SelectedItem="{Binding Author}"
. (Author
being a virtual property of Book
)
The ComboBox displays the Author list correctly. However, it doesn't seem to display the Book's Author as its SelectedItem.
Is this because I am using a different instance of DbContext? If so, how can I rectify this problem?