Restoring window state is not working correctly
Author: MartinZikmundCreated Oct 1, 2024Updated Sep 17, 2026
The full screen state does not seem to work when restoring the window presenter or I am probably missing something. I created a sample project where you can see the behavior.
https://github.com/user-attachments/assets/36f8d4cc-47fa-4426-8755-57171fa55454
MainWindow = builder.Window;
MainWindow.Closed += OnMainWindowClosed;
RestoreWindowPosition();
#if DEBUG
MainWindow.EnableHotReload();
#endif
MainWindow.SetWindowIcon();
Host = await builder.NavigateAsync<Shell>();
}
private void OnMainWindowClosed(object sender, WindowEventArgs args)
{
SaveWindowPosition();
}
private void SaveWindowPosition()
{
var settings = ApplicationData.Current.LocalSettings;
settings.Values["WindowWidth"] = MainWindow!.AppWindow.Size.Width;
settings.Values["WindowHeight"] = MainWindow.AppWindow.Size.Height;
settings.Values["WindowX"] = MainWindow.AppWindow.Position.X;
settings.Values["WindowY"] = MainWindow.AppWindow.Position.Y;
settings.Values["Presenter"] = (int)MainWindow.AppWindow.Presenter.Kind;
}
private void RestoreWindowPosition()
{
var settings = ApplicationData.Current.LocalSettings;
if (settings.Values.TryGetValue("WindowWidth", out var width) &&
settings.Values.TryGetValue("WindowHeight", out var height) &&
settings.Values.TryGetValue("WindowX", out var x) &&
settings.Values.TryGetValue("WindowY", out var y) &&
settings.Values.TryGetValue("Presenter", out var p))
{
var size = new SizeInt32 { Width = (int)width, Height = (int)height };
var position = new PointInt32 { X = (int)x, Y = (int)y };
MainWindow!.AppWindow.Resize(size);
MainWindow.AppWindow.Move(position);
MainWindow.AppWindow.SetPresenter((AppWindowPresenterKind)p);
}
}Originally posted by @ArchieCoder in https://github.com/unoplatform/uno/discussions/18338#discussioncomment-10810103
Source: unoplatform/uno