C# 使用Caliburn.Micro同时显示两个WPF窗口
我需要在启动时在单独的窗口中同时显示两个WPF控件。父窗口的类型相同,用户控件(和父窗口)在单独的程序集中定义,该程序集仅由主体项目引用。我正在使用Caliburn.Micro作为MVVM框架,并为IoC使用Ninject。如何做到这一点 所有视图模型都是从PropertyChangedBase派生的。我已经设置了AppBootstrapper来定义Caliburn.Micro标准绑定,例如WindowManager:C# 使用Caliburn.Micro同时显示两个WPF窗口,c#,wpf,mvvm,ninject,caliburn.micro,C#,Wpf,Mvvm,Ninject,Caliburn.micro,我需要在启动时在单独的窗口中同时显示两个WPF控件。父窗口的类型相同,用户控件(和父窗口)在单独的程序集中定义,该程序集仅由主体项目引用。我正在使用Caliburn.Micro作为MVVM框架,并为IoC使用Ninject。如何做到这一点 所有视图模型都是从PropertyChangedBase派生的。我已经设置了AppBootstrapper来定义Caliburn.Micro标准绑定,例如WindowManager: _kernel.Bind<IControl1>().To&l
_kernel.Bind<IControl1>().To<Control1ViewModel>().InSingletonScope();
_kernel.Bind<IControl2>().To<Control2ViewModel>().InSingletonScope();
_kernel.Bind<IParentWindow>().To<ParentWindowViewModel>();
\u kernel.Bind()To().InSingletonScope();
_kernel.Bind().To().InSingletonScope();
_kernel.Bind().To();
并为创建Control1的OnStartup创建了覆盖:
DisplayRootViewFor<IWindow1>();
DisplayRootViewFor();
用户控件作为窗口上下文提供给ContentControl中的父窗口,如下所示:
<ContentControl x:Name="WindowView"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
cal:View.Context="{Binding ViewContext}"
cal:View.Model="{Binding WindowContent}" />
最后,我还提供了对SelectAssembly的覆盖,以便Caliburn.Micro可以在dll中找到视图和视图模型:
protected override IEnumerable<Assembly> SelectAssemblies()
{
var assemblies = base.SelectAssemblies().ToList();
assemblies.Add(typeof(IControl1).GetTypeInfo().Assembly);
return assemblies;
}
受保护的重写IEnumerable SelectAssemblys()
{
var assemblies=base.SelectAssemblies().ToList();
Add(typeof(IControl1.GetTypeInfo().Assembly);
返回组件;
}
我尝试了几种可能的解决方案,但没有一种有效:
var parentWindow = _kernel.Get<IParentWindow>();
var parentWindow=\u kernel.Get();
为父窗口上下文提供用户控件:
parentWindow = _kernel.Get<IControl1>();
parentWindow=\u kernel.Get();
使用WindowManager.ShowWindow打开窗口:
_kernel.Get<IWindowManager>().ShowWindow(parentWindow, null, windowSettings);
\u kernel.Get().ShowWindow(parentWindow,null,windowSettings);
只需对第二个窗口重复此过程:
var window2 = _kernel.Get<IParentWindow>();
window2.WindowContent = _kernel.Get<IControl2>() ;
_kernel.Get<IWindowManager>().ShowWindow(window2, null, windowSettings);
var window2=_kernel.Get();
window2.WindowContent=_kernel.Get();
_kernel.Get().ShowWindow(window2,null,windowSettings);
这将使用WPF中的Caliburn.Micro创建两个窗口,其中包含在外部程序集中定义的用户控件