I use Entity Framework and Caliburn.Micro to implement an MVVM application.
Basically, I created AuthorModel and BookModel in a one to many relationship - to an Author who has several books and books that have only one author.
I have a SelectBookWindow where I use a DbContext to load an ObservableCollection<Book>
, from where I select the book that I want to view / edit. Then I pass the selected book as a parameter to EditBookWindow, where I have a combobox listing all the authors, but with the selected author.
Here I load the ObservableCollection<Author>
using another DbContext instance and set it as combobox ItemsSource
, as well as do SelectedItem="{Binding Author}"
. ( Author
is a virtual property of Book
)
ComboBox displays the list of authors correctly. However, it does not appear to display the Book Author as a SelectedItem.
Is it because I'm using another instance of DbContext? If so, how can I fix this problem?
source share