ViewModel with two Views - with PropertyGrid SelectedObject

Topics: UI Architecture
Feb 21, 2013 at 11:44 PM
I have a ViewModel with two Views using the cal:View.Context feature. It's working fine, with the DC available in both Views.

But the right hand view is a PropertyGrid, and I want to set its SelectedObject to the instance of different controls that are on the left hand side view. There's a bit of switching involved via a ComboBox.

So I would need to get the instance of the controls back to the ViewModel.
That would break the separations, because there is a UI object being handled within the ViewModel.

I can of course get hold of the View instances from OnViewAttached, where it gets called three times, as expected. And I guess find the named controls withing the views.

I guess this is a MVVM problem whenever a View has a Control on it (like a property grid) which itself deals with controls!

Can anyone suggest an approach that's in harmony with V VM separation.

Feb 22, 2013 at 10:52 AM
I thought of a way, using an Attached Property on the ViewModel.
Then I found this article

Works fine!
But is this approach reasonable?