WPF: What is between the Initialized and Loaded event?

前端 未结 3 764
悲哀的现实
悲哀的现实 2021-02-02 11:30

I want to run some code when the Window or Control is first displayed. I can\'t use Loaded because that can fire more than once. I can\'t use Initialized because that is done by

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-02 11:57

    Unfortunately there is no such event. You can use a boolean in the Loaded Method to make sure your stuff only fires once -

    if(!IsSetUp)
    {
       MySetUpFunction();
       IsSetUp = true;
    }
    

    Check out the WPF Windows lifetime events here:

    http://msdn.microsoft.com/en-us/library/ms748948.aspx#Window_Lifetime_Events


    (source: microsoft.com)

提交回复
热议问题