MVVM Binding - creating a control in a View, how bind to property in ViewModel? -
we add tabcontrols our application @ runtime. each tabcontrol given viewmodel datacontext. add tabcontrols sending message main app view; message contains viewmodel used datacontext.
from main app viewmodel, add tabitems tab controls sending message main app view create tabitem , add specified tabcontrol.
i'd bind properties of tabitem properties of tabcontrol's viewmodel; needs done programmaticaly, of course.
since tabcontrol , tabitem don't know viewmodels (only datacontext), how specify properties of viewmodel bind tabitem properties too?
thanks advice...
messenger.default.register<addtabcontrolmessage>(this, m => { tabcontrol tc = new tabcontrol(); tc.datacontext = m.viewmodel; // etc. } );
you can cast datacontext type of viewmodel , access properties way.
tc.someproperty = ((myviewmodel)datacontext).somevmproperty;
Comments
Post a Comment