Application.OnLaunched(LaunchActivatedEventArgs) 方法

定義

啟動應用程式時叫用。 覆寫這個方法以執行應用程式初始化,並建立新的視窗。

protected:
 virtual void OnLaunched(LaunchActivatedEventArgs ^ args) = OnLaunched;
void OnLaunched(LaunchActivatedEventArgs const& args);
protected virtual void OnLaunched(LaunchActivatedEventArgs args);
function onLaunched(args)
Protected Overridable Sub OnLaunched (args As LaunchActivatedEventArgs)

參數

範例

使用 OnLaunched 來建立並啟動主視窗。 (當您建立 WinUI 3 app.) 時,Visual Studio 專案範本會提供此程式碼

private Window m_window;

protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
    m_window = new MainWindow();
    m_window.Activate();
}

適用於

另請參閱