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

后端 未结 2 1689
生来不讨喜
生来不讨喜 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: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.

提交回复
热议问题