首先,关于数据绑定几个问题:棱镜V4,MEF WPF数据绑定
- 是对设置到代码隐藏控件的默认的DataContext?例如,如果我在test.xaml.cs中有一个变量
orderNumber
,我可以在xaml{Binding orderNumber}
中像这样引用它吗? - 是否正确,我只能绑定到对象的属性?
我在单独的模块/程序集中有一个Prism服务,我通过MEF将其导入到Shell应用程序中。我试图对它进行数据绑定,但似乎没有工作。
我的解决方法如下。 在我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;
}
有没有办法来设置前一个对象XAML DataContext的设定 - 特别是在关于MEF /棱镜的情况?在我的功能区对象上,我尝试了DataContext="{Binding MenuService}"
,但没有奏效。
@Chris:在功能区或RibbonWindow中定义了MenuService吗? –
IRibbonService接口和RibbonService类在一个名为Infrastructure的单独项目中声明/实例化,并使用MEF导出...然后使用上面问题中使用的代码导入RibbonWindow。 –
我试着做这样的事情http://serialseb.blogspot.com/2007/10/wpf-tips-8-use-your-code-behind-for.html其中根xaml元素有一个自我DataContext,但没有数据绑定,也许是因为我需要一个DependencyProperty(不确定,我需要阅读它的用途) –