lahjaton_j lahjaton_j - 3 months ago 65
C# Question

Force WPF application to maximize on Windows startup

I have a WPF app that installed on Windows 10 Pro via ClickOnce and uses MahApps.Metro.

It is set to launch on Windows boot with a non-admin account that has no password. Tablet mode is enabled.

I want the application pop up full screen to create kiosk-like experience, however the app starts minimized when launching on boot. To clarify, the WindowState is Maximized, but Windows does not show it, instead it shows the start screen. It launches fullscreen maximized when launching manually.

Here is some code, however I guess this is more of a configuration problem than code problem:

This is how I set the launch on boot:

RegistryKey rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
string startPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs)
+ @"\Publisher\AppName.appref-ms";
rkApp.SetValue("AppName", startPath);

This is MainWindow.xaml

<Controls:MetroWindow x:Class="AppName.MainWindow"
IgnoreTaskbarOnMaximize="True" ShowTitleBar="False" WindowStyle="None" WindowState="Maximized">


The solution (hack) was to open any other window (e.g. powershell) on startup using Task Scheduler, and after another window is open, we can call Alt+Tab in a powershell script using.

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")