WPF Control: where is “OnLoaded” virtual function?

后端 未结 2 1327
情话喂你
情话喂你 2021-02-19 21:48

In WinForm\'s control, there is an OnLoaded virtual function, but this seems to be missing in WPF control. I found this function very useful in some situations. For example, I c

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 22:44

    You can attach to the Loaded event of your Window object and do what you want to do inside the event handler (assuming you are using c#):

    public MyWindow() //constructor
    {
      this.Loaded += MyWindow_Loaded;
    }
    
    private void MyWindow_Loaded(object sender, RoutedEventArgs e)
    {
      // do your stuff here
    }
    

提交回复
热议问题