Hunter Winchester
Hunter Winchester

Reputation: 305

Updating Main Window from page in a frame

I'm currently developing a WPF application using the MVVM framework. And I have this functionality: enter image description here

I have a main window which has a combo box and frame (where I put my pages) and a view model. One of the pages in that frame is where a user can add a data and these data are used to populate the combo box in the main window. My problem is how to automatically update the items in the combo box after adding a data from that page. Btw, this page has a different view model too.

Thanks.

Upvotes: 0

Views: 621

Answers (3)

Lukáš Koten
Lukáš Koten

Reputation: 1253

You can pass the Source DataContext of ComboBox (ObservableCollection) to page ViewModel so you can simply modify the collection from Page view model.

Upvotes: 0

grek40
grek40

Reputation: 13458

You can establish an event in the page viewmodel for changed data. Then subscribe to those events within the window viewmodel and update the combobox items accordingly.

Upvotes: 1

Rahul Baruri
Rahul Baruri

Reputation: 709

You have access to the parent window from iframe via window.top. You have to write this code in your page what you have loaded in iFrame.

window.top.document.getElementById("combobox_element_id").value='Your New Value';

best of luck

Upvotes: 0

Related Questions