Nested Control DataContext #15661
Unanswered
jaymarvels
asked this question in
Q&A
Replies: 1 comment
-
Your items need to raise property changed, not the collection itself |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My understanding from this diagram:
Is that a control inside a control can get use to context "higher up" - "... control defined in a window can use the data context of the window; or (as above) a control in a control in a window can use the window's data context..."
So I have my MainWindow and inside this I have my MainView, inside my MainView I have other controls (views), my MainView has its own MainViewModel and in my App.axmal.cs I set up my DI for them:
In my MainViewModel I have an
ObservableCollection
which I can display in a DataGrid on my MainView without issue.One of my controls - CityPage - inside the MainView, wants to use this ObservableCollection in its own View, so I attempt something like this:
It complains about the xData type so I have to add in
x:DataType="viewModels:MainViewModel"
and at this point it populates the DataGrid using the ObservableCollection from the "parent" control.One of the issues I am seeing though is if I try and make a change to a value in the DataGrid thats on the CityPage this doesn't get reflected/updated on the bound ObservableCollection that is displayed on the MainView. Doing it the other way around (so changing on the MainView) does automatically change the value of the child control (CityPage).
In my MainViewModel I am doing:
So it should fire off the RaiseAndSetIfChanged.
Am I missing something in the way datacontext is used and passed around? As you can see I have tried "TwoWay" mode too without much luck.
Beta Was this translation helpful? Give feedback.
All reactions