我已将Bootstrapper放在一个单独的程序集中,而不是ViewModels和Views。 但是,当没有其他需要解析相应视图的Screen时,DesignTime支持似乎适用于简单的* ViewModel-> *视图可视化。但是我不能让它为子ViewModels运行。我得到了一个异常......
具有子ViewModel的容器:
<UserControl ...
d:DataContext="{d:DesignInstance Type=vm:DesignSomeContainerViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True ... >
<ContentControl cal:View.Model={Binding PropertyWithChildModel} />
// where PropertyWithChildModel is another Screen
属性中的屏幕在DesignTime上显示时是正常的,但不在另一个View的ContentControl内...然后DesignTime支持被破坏。我遵循了Caliburn Micro Documentation建议的指导。但是在使用嵌套解析时没有任何关于专业的说法。
我的项目结构:
[Application.exe]
- MyNameSpace.ApplicationName
- Bootstrapper (knows assemblies with views)
[Satellite.dll]
- MyNameSpace.SomeWhere
- SomeContainerViewModel
- [DesignTime]/DesignSomeContainerViewModel (Folder is Namespaceprovider)
- SomeContainerView (SomeContainerView is set to look at DesignSomeContainerViewModel at DesignTime)
- [MyChilds]/SomeChildViewModel
- [DesignTime]/DesignSomeChildViewModel
- [MyChilds]/SomeChildView (SomeChildView is set to look at DesignSomeChildViewModel)
班级模型:
public interface ISomeChildViewModel
{
string SomeValue {get;}
}
// should not be used during design time
public class SomeChildViewModel : Screen, ISomeChildViewModel
{
// real implementation
}
// this is used at design time
public class DesignSomeChildViewModel : Screen, ISomeChildViewModel
{
public DesignSomeChildViewModel()
{
this.SomeValue = "Hello World!";
// showing up correctly in the Xaml View at DesignTime
}
string SomeValue {get;set;}
}
public interface ISomeContainerViewModel
{
IScreen PropertyWithChildModel{get;}
}
// should not be used during design time
public class SomeContainerViewModel : Screen, ISomeContainerViewModel
{
// real implementation
}
// used during design time
public class DesignSomeContainerViewModel : Screen, ISomeContainerViewModel
{
public DesignSomeContainerViewModel ()
{
// this assignment leads to an exception that the IoC is not ready
// "IoC is not initialized."
this.PropertyWithChildModel = new DesignSomeChildViewModel();
}
IScreen PropertyWithChildModel
{
get { return propertyWithChildModel; }
set
{
this.propertyWithChildModel=value;
this.NotifyOfPropertyChange();
}
}
}
我已尝试/检查的内容: