コードが現在デザイン モード (Blend または Visual Studio など) で実行されているかどうかを確認できるように、利用可能なグローバル状態変数を知っている人はいますか?
次のようになります。
//pseudo code:
if (Application.Current.ExecutingStatus == ExecutingStatus.DesignMode)
{
...
}
これが必要な理由は、アプリケーションが Expression Blend のデザイン モードで表示されている場合、ViewModel で代わりに、デザイナーがデザイン モードで表示できるモック データを含む "Design Customer クラス" を使用することです。
ただし、アプリケーションが実際に実行されているときは、当然、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);
}
}
}