一個更好的調整是用這樣的方式(在卡利實現,但不是微之一)。 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