-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It's not possible to restore window position, size and state #14517
Comments
@sinatrocious I cannot reproduce it or I am not able to understand what you expect. Please file a minimal sample attached. Thx. |
Two blockers I ran into (Windows OS):
Would take some digging to figure out if Avalonia is using The least number of resize operations I can get at startup and still have memory is using both public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
WindowStartupLocation = Controls.WindowStartupLocation.Manual,
Position = new(0, 0),
Width = 100,
Height = 100
};
}
base.OnFrameworkInitializationCompleted();
} protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
WindowState = WindowState.Maximized;
} Alternatively, if you need this to happen in one spot, you can use the Dispatcher at (I think) the cost of an extra window resizing operation: protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
Width = 100;
Height = 100;
Position = new(0, 0);
Dispatcher.UIThread.Post(() =>
{
WindowState = WindowState.Maximized;
});
} |
would this PR fix that issue? #14470 |
@stevemonaco, thanks for digging a new solution for me. In WPF I often need to use dispatcher-invoke-trick, so I am ok with invoking public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var window = desktop.MainWindow = new MainWindow
{
DataContext = new MainViewModel()
};
window.Width = 100;
window.Height = 100;
window.Position = new(0, 0);
Dispatcher.UIThread.InvokeAsync(() =>
{
window.WindowState = WindowState.Maximized;
});
}
}
Not sure. |
Yesterday I rewrote #14470 to entirely change the way in which a window's restored size is set, including for maximised windows. Please test with the PR again, if you tried it earlier. |
@TomEdwardsEnscape, I can report bugs, but I am unable to test PRs, sorry. |
Why? |
Let me know if this issue is still reproducible. |
@maxkatz6, just tried with 11.1.0, the issue is not reproducable anymore. |
Describe the bug
No matter where I set window properties, such as
Width
,Height
,Position
andWindowState
, the final values of displayed window properties is rather undeterministic. There is some logic running behind, which alters values I set and I am not yet able to figure it out.To Reproduce
Here are my attempts
App.axaml.cs
:Doesn't work, the window size is wrong. Try to comment
WindowState
line to see expected size.MainWindow.axaml.cs
:Doesn't work, the window size and position are wrong! Try to comment
WindowState
line to see expected size and position.Expected behavior
I expect to be able to set window state (maximized, minimized or normal), size, position, etc. and have exactly that values, not something different.
Environment
Additional context
My story begins 9 months ago when I tried to simply save window state and restore it on next start. But this just didn't worked: window shifts after several restarts, the window size or position gets reset... Today I have even more ugly bug (can't reproduce, but it motivate me to write a bug report) where maximized window is not occupying whole screen, but is shifted to the middle ><
I was waiting for #3387 to be fixed and noticed just today, that it was simply closed. Great. The suggested there workaround to utilize
OnOpened
worked for some time, then stopped working. Then after I changed the order of setting properties (window state before position/size) it was working again and today everything stops working another time and I have ugly maximized window which is not maximized. ><So I tried to reproduce the bug and it was too easy ><
Perhaps I am doing something wrong? Then show me, I'll refer to your attempt in my next bug report, when this thing stops working again =)
The text was updated successfully, but these errors were encountered: