有没有人知道是否有一些全局状态变量可用,以便我可以检查代码当前是否在设计模式下执行(例如在 Blend 或 Visual Studio 中)?
它将类似于:
//pseudo code:
if (Application.Current.ExecutingStatus == ExecutingStatus.DesignMode)
{
...
}
我需要这样做的原因是,当我的应用在Expression Blend的设计模式下显示时,我希望ViewModel使用“设计客户类”,该类中包含设计师可以在设计模式下查看的模拟数据。然而,当应用程序实际执行时,我当然希望ViewModel使用返回真实数据的真实Customer类。
目前,我通过让设计师在开始工作之前进入ViewModel并将“ApplicationDevelopmentMode.Executing”更改为“ApplicationDevelopmentMode.Designing”来解决这个问题。
public CustomersViewModel()
{
_currentApplicationDevelopmentMode = ApplicationDevelopmentMode.Designing;
}
public ObservableCollection<Customer> GetAll
{
get
{
try
{
if (_currentApplicationDevelopmentMode == ApplicationDevelopmentMode.Developing)
{
return Customer.GetAll;
}
else
{
return CustomerDesign.GetAll;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}