c# - Prism v4, MEF WPF DataBinding -


first, few questions regarding databinding:

  • is default datacontext control set codebehind? example, if have variable ordernumber in test.xaml.cs, can reference in xaml {binding ordernumber}?
  • is correct can databind properties of object?

i have prism service in separate module/assembly import shell application via mef. i'm trying databind on doesn't appear working.

my workaround below. in shell.xaml.cs:

[import(allowrecomposition = false)] private iribbonservice _menuservice; public iribbonservice menuservice {         {         return _menuservice;     } }   public void onimportssatisfied() {     debug.writeline("imports satisfied", "prism");     this._modulemanager.loadmodulecompleted += new eventhandler<loadmodulecompletedeventargs>(modulemanager_loadmodulecompleted);      //todo figure out how bind ribbon     ribbon.datacontext = _menuservice;     ribbonappmenu.datacontext = _menuservice.applicationmenudata; } 

is there way set datacontext in xaml prior object being set - in regards mef / prism scenario? on ribbon object tried datacontext="{binding menuservice}" didn't work.

is default datacontext control set codebehind? example, if have variable ordernumber in test.xaml.cs, can reference in xaml {binding ordernumber}?

no. default, there no datacontext, , inherited parent using hierarchy mechanisms in wpf. need explicitly set datacontext control, if want have one.

is correct can databind properties of object?

yes. can bind properties. if want 2 way binding work, object must dependencyobject or implement inotifypropertychanged.

is there way set datacontext in xaml prior object being set - in regards mef / prism scenario? on ribbon object tried datacontext="{binding menuservice}" didn't work.

this attempt set datacontext menuservice property of containing datacontext using hierarchy (ie: parent control/window's datacontext's menuservice property). can't bind set datacontext.

you can create new object in xaml use datacontext, or have containing object provide datacontext you.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -