【发布时间】:2011-03-09 14:09:35
【问题描述】:
我的请求是similar to this。
我正在使用 MvvmLight,Viewmodel 信息在设计时和运行时正确显示。但是我想把它抽象成一个服务类。所以我有我的模拟服务和实现 IService 的真实服务。
在 app.xaml 的代码隐藏中,我正在检查设计时间,然后根据检查返回的内容调用我的服务加载器上的方法。
if (IsInDesignModeStatic)
{
ServiceLoader.LoadDesignTimeServices();
}
else
{
ServiceLoader.LoadRunTimeServices();
}
public sealed class ServiceLoader
{
private ServiceLoader()
{
}
public static void LoadDesignTimeServices()
{
ServiceContainer.Instance.AddService<IQuestionsService>(new dt.QuestionsService());
}
public static void LoadRunTimeServices()
{
ServiceContainer.Instance.AddService<IQuestionsService>(new rt.QuestionsService());
}
}
这在运行时工作得很好,但在设计时不行。如果我真的在我的视图模型中使用设计时具体实现:
if (IsInDesignMode)
{
//var s = Infrastructure.GetService<IQuestionsService>();
var s = new ReadmissionTrackingApplication.Client.Services.DesignTime.QuestionsService();
QuestionCollectionView_Refresh(s.getQuestions());
}
else
{
//Listens for New Questionairre request. It receives the current ReadmitPatientResult
Messenger.Default.Register<fnReadmitPatientList_Result>(this, ReceiveNewQuestionairreRequest);
//TODO for testing only
ReceiveNewQuestionairreRequest(null);
}
它出现在 Blend 中。我需要做什么才能允许访问混合中的模拟服务?我想我记得读过我必须以某种方式将服务加载器添加到我的应用程序资源中,类似于使用视图模型完成的操作......但我不知道它需要如何完成,我认为它与 vm 的完成方式不同,因为我不是在视图中访问服务,而是从视图模型中访问。
【问题讨论】:
标签: silverlight-4.0 expression-blend mvvm-light