一个更好的调整是用这样的方式(在卡利实现,但不是微之一)。 http://caliburnmicro.codeplex.com/discussions/265502
,首先您需要定义用于存储用来发现视图中的相关数据属性:
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class ViewAttribute : Attribute
{
public object Context { get; set; }
public Type ViewType { get; private set; }
public ViewAttribute(Type viewType)
{
ViewType = viewType;
}
}
其附加到视图模型。
[View(typeof(MyView))]
public class MyViewModel : Screen
然后,你需要在你的引导程序来改变LocateTypeForModelType到这样的事情:
void Initialize()
{
var baseLocate = ViewLocator.LocateTypeForModelType;
ViewLocator.LocateTypeForModelType = (modelType, displayLocation, context) =>
{
var attribute = modelType.GetCustomAttributes(typeof(ViewAttribute), false).OfType<ViewAttribute>().Where(x => x.Context == context).FirstOrDefault();
return attribute != null ? attribute.ViewType : baseLocate(modelType, displayLocation, context);
};
}
所以,你想出货几个不同的DLL,每一个都有自己的你的意见的副本,并在运行时你会决定加载哪一个?如果没有,你需要澄清你的意思是“供应视图文件夹运行时间”。 –
@JoeWhite我只想在xaml中提供视图。我不会放入dll。所以当程序启动时,它应该加载来自xaml文件的所有视图。 –
你没有提供足够的细节。动态启动后是否需要切换主题?或者当你的应用程序重新启动时?这将决定你需要采取哪条路线。 – jonathanpeppers