Attempts to activate the application window by bringing it to the foreground and setting the input focus to it.
public: virtual void Activate() = Activate;
public void Activate();
Public Sub Activate ()
If you use the default app templates from Microsoft Visual Studio, Window.Activate is part of the initial code in the app.xaml code-behind file. Specifically, Activate is called from the default OnLaunched override. In cases where the template produces a page navigation experience, previous states are detected so that the navigation framework isn't overwritten if it already existed, but Activate is called regardless.
Calling Activate is required for all app activation scenario, not just app launch.
This method is important for the correct operation of an app. If an app does not call Activate on the Current window, and the app is not visible on screen, then the app will be terminated after 15 seconds. If the app or its splash screen is kept on screen there is no time limit, but eventually the app needs to call Activate to progress. Also, certain app contracts extend the time limit.
You can modify the default OnLaunched implementation in order to delay calling Activate. You might do this to have all app rendering be complete before the main Window is shown. For example, a delay can be useful to finish loading Image source files in the initial UI. (These load asynchronously and it's impractical to handle ImageOpened from app.xaml code-behind.) On the other hand, delaying the call can create an undesirable user experience if the splash screen is visible for too long.
For secondary windows, you also need to call Activate. For more info about secondary windows, see Show multiple views for an app.