What's the difference between the Window.Loaded and Window.ContentRendered events

后端 未结 4 1638
难免孤独
难免孤独 2020-12-13 06:00

What\'s the difference between the Window.Loaded and Window.ContentRendered events in WPF? Is the ContentRendered event called first?

4条回答
  •  Happy的楠姐
    2020-12-13 06:35

    This is not about the difference between Window.ContentRendered and Window.Loaded but about what how the Window.Loaded event can be used:

    I use it to avoid splash screens in all applications which need a long time to come up.

        // initializing my main window
        public MyAppMainWindow()
        {
            InitializeComponent();
    
            // Set the event
            this.ContentRendered += MyAppMainWindow_ContentRendered;
        }
    
        private void MyAppMainWindow_ContentRendered(object sender, EventArgs e)
        {
            // ... comes up quick when the controls are loaded and rendered
    
            // unset the event
            this.ContentRendered -= MyAppMainWindow_ContentRendered;
    
            // ... make the time comsuming init stuff here
        }
    

提交回复
热议问题