第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有一種方法可以檢查WPF當前是否在設(shè)計模式下執(zhí)行?

有沒有一種方法可以檢查WPF當前是否在設(shè)計模式下執(zhí)行?

C#
幕布斯6054654 2019-10-15 14:48:58
有誰知道一些可用的全局狀態(tài)變量,以便我可以檢查代碼當前是否正在設(shè)計模式下執(zhí)行(例如在Blend或Visual Studio中)?它看起來像這樣://pseudo code:if (Application.Current.ExecutingStatus == ExecutingStatus.DesignMode) {    ...}我需要這樣做的原因是:當我的應(yīng)用程序在Expression Blend中以設(shè)計模式顯示時,我希望ViewModel改為使用其中包含模擬數(shù)據(jù)的“ Design Customer類”,設(shè)計人員可以在設(shè)計模式下進行查看。但是,當應(yīng)用程序?qū)嶋H執(zhí)行時,我當然希望ViewModel使用返回真實數(shù)據(jù)的真實Customer類。目前,我可以通過讓設(shè)計者著手解決這個問題,在他進行設(shè)計之前,先進入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);        }    }}
查看完整描述

3 回答

?
拉風(fēng)的咖菲貓

TA貢獻1995條經(jīng)驗 獲得超2個贊

我相信您正在尋找具有DependencyObject的GetIsInDesignMode。


就是


// 'this' is your UI element

DesignerProperties.GetIsInDesignMode(this);

編輯:使用Silverlight / WP7時,應(yīng)使用,IsInDesignTool因為GetIsInDesignMode有時在Visual Studio中可能返回false:


DesignerProperties.IsInDesignTool

編輯:最后,出于完整性考慮,WinRT / Metro / Windows Store應(yīng)用程序中的等效項是DesignModeEnabled:


Windows.ApplicationModel.DesignMode.DesignModeEnabled


查看完整回答
反對 回復(fù) 2019-10-15
?
至尊寶的傳說

TA貢獻1789條經(jīng)驗 獲得超10個贊

您可以執(zhí)行以下操作:


DesignerProperties.GetIsInDesignMode(new DependencyObject());


查看完整回答
反對 回復(fù) 2019-10-15
?
躍然一笑

TA貢獻1826條經(jīng)驗 獲得超6個贊

public static bool InDesignMode()

{

    return !(Application.Current is App);

}

可在任何地方工作。我用它來阻止數(shù)據(jù)綁定視頻在設(shè)計器中播放。


查看完整回答
反對 回復(fù) 2019-10-15
  • 3 回答
  • 0 關(guān)注
  • 832 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號