Understand WPF Window Events

后端 未结 2 1014
花落未央
花落未央 2020-12-08 03:22

I see Windows have a Loaded event, but not a Loading event (as there is Closing and Closed events).

My expectatio

2条回答
  •  太阳男子
    2020-12-08 04:00

    You can override OnStartup() in App.xaml.cs, and do stuff before calling base.OnStartup(e);. I just checked and this is fired before the window's constructor.

    Alternatively, set the window's visibility to Hidden in its xaml file, do your initialization in the constructor and then set the visibility to Visible once done. This won't remove the delay, but the delay is only caused by whatever your initialization code is doing, so it's unavoidable unless you go asynchronous.

提交回复
热议问题