First, a few questions regarding databinding:
- Is the default DataContext for a control set to the codebehind? For example, if I have a variable
orderNumber
in test.xaml.cs, can I just reference it like so in the xaml{Binding orderNumber}
? - Is it correct that I can only databind to properties of an object?
I have a Prism service in a separate module/assembly that I import into my Shell application via MEF. I'm trying to databind on it but it doesn't appear to be working.
My workaround is below. In my Shell.xaml.cs:
[Import(AllowRecomposition = false)]
private IRibbonService _menuService;
public IRibbonService MenuService
{
get
{
return _menuService;
}
}
public void OnImportsSatisfied()
{
Debug.WriteLine("Imports satisfied", "Prism");
this._moduleManager.LoadModuleCompleted += new EventHandler<LoadModuleCompletedEventArgs>(moduleManager_LoadModuleCompleted);
//TODO figure out how to properly bind to the ribbon
Ribbon.DataContext = _menuService;
RibbonAppMenu.DataContext = _menuService.ApplicationMenuData;
}
Is there a way to set the datacontext in xaml prior to an object being set - specifically in regards to MEF / Prism scenario? On my ribbon object I tried DataContext="{Binding MenuService}"
but that didn't work.