Hi @水 知 ,
Glad you found a solution, and thanks for linking the thread.
The manifest attributes are the blocker. Most guides are written for UWP, where the windows.startupTask extension is declared with Executable and EntryPoint. Both are optional in the schema, and in a WinUI 3 / Windows App SDK app they break the startup activation — the app gets launched at sign-in but never comes up. Removing them fixes it:
<uap5:Extension Category="windows.startupTask">
<uap5:StartupTask TaskId="MyAppId" Enabled="false" DisplayName="MyApp startup" />
</uap5:Extension>
There's no OnActivated to override in WinUI 3. That's a UWP-only pattern, which is why the older guidance doesn't apply. Your app always comes in through OnLaunched, and LaunchActivatedEventArgs reports Launch even when Windows started it at sign-in. To detect a startup launch, read the activation args directly:
using Microsoft.Windows.AppLifecycle;
var args = AppInstance.GetCurrent().GetActivatedEventArgs();
if (args.Kind == ExtendedActivationKind.StartupTask)
{
// launched at sign-in — e.g. start minimised to tray
}
Also keep in mind that this only works for packaged apps. Unpackaged, the manifest extension does nothing — you'd need a Startup folder shortcut or a Run registry entry.
If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance or provide feedback.
Thank you.