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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -