Indeed, we have something sophisticated enough, and we go with the view model approach for the MC (markup control).
In this case, how do we update the parent viewmodel property? I don’t see SetValueToSource() available in the view model of the MC.
You can use your viewmodel page and use _root.SomeVar inside your control. Or pass it as a parameter and do the same with _control.SomeVar. Or maybe I’m not sure what you are looking for
If you need to update the object itself, I’d use a control property instead of passing it as data context. If you only need to update one property of the view model, you can do something like ((MyViewModel)this.DataContext).SomeProperty = 0;
I was, again!, stuck with the way of thinking from WebForms, where it was a must to have property-parameters on the child UserControl in the markup and fed values in them by the parent.
Instead I’ve deleted the markup control properties from the markup of the parent (argh, got confused here in naming these) and obtained the both ways(parent->child & child->parent) communication directly through the properties of the view model of the child, as its instance was a property of the parent’s view model.
LE: hmm, if I’m not mistaking, the downside of this may be considered to be that you no longer have a visual orientation in the markup of linking what parent properties to what parts of the child. So I’ve labeled/grouped them like such in the child view model, to quickly distinguish them from the rest of the properties:
The upside being that I’ve got rid of the baseType .cs file entirely.
I see that I don’t have it in the view model code. Again, this is the view model of a child markup control. What I’ve tried to achieve seems now dependent on the baseType .cs file to exist and have some DotvvmProperty properties declared. But this I no longer prefer (as it would mean to bring back that additional code file with its boiler plate which is not small).
I see, sorry, I though you want to do the update from the MarkupControl class. I think I don’t really understand what are you trying to do. If you want to update the parent view model from the Init method, you’d have to pass in a reference to parent in the constructor or in the parent’s Init.
Nevermind, I understand now that you meant that code to be used from the baseType file/class and not from the view model. LE: I’ve edited my first reply.