How to check if i'm in run-time or design time?

后端 未结 2 1691
生来不讨喜
生来不讨喜 2021-01-05 23:47

I developed some userControl that contain some information check on the \'IsVisible\' method ( override method ).

When i using this usercontrol on some window - i se

相关标签:
2条回答
  • 2021-01-06 00:23

    DesignerProperties.GetIsInDesignMode(this); This would return true if you are in design-time.

    0 讨论(0)
  • 2021-01-06 00:30
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
                Console.WriteLine("The main window is in design mode.");
        }
    }
    

    The other answer is technically correct but I am providing this one to clarify the namespace and the usage.

    0 讨论(0)
提交回复
热议问题