有誰知道一些可用的全局狀態變量,以便我可以檢查代碼當前是否正在設計模式下執行(例如在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); } }}
有沒有一種方法可以檢查WPF當前是否在設計模式下執行?
幕布斯6054654
2019-10-15 14:48:58