0.9.0-preview7
it seems it happen if an element is expanded while the windows is minimized. It seems the auto resize is broken then. (or in general, any resize that happen during minimized state)
The problem happens even if SizeToContent="Manual".
The root of the problem is that when the window is restored, Avalonia seems to set the ClientSize back to what it was before it has been minimized, regardless of whether SizeToContent and even if this ClientSize changed while the windows was minimized.
I think the problem here is that there's no way of telling whether a resize was caused by an auto-resize, a user resize or a minimize/restore.
A user resize always results in auto-resizing being turned off, but we need a way to tell where the resize event came from. I'm not sure there is any of way of knowing that?
I tried to solve this here https://github.com/AvaloniaUI/Avalonia/pull/2383 but gave up... The description only mentions X11, but this was also an attempt to fix auto-resizing on other platforms too. Unfortunately I think my solution was flawed. Probably need to revisit this soon.
@jmacato I don't think this can be fixed for 0.9, it's not a simple problem.
@grokys got it, i included it to 0.9 for posterity; removing milestones now
@NicolasDorier when you say that "it happens even if SizeToContent="Manual"" - what happens? The problem is "Not sizing to content anymore", right? If SizeToContent="Manual" then it shouldn't be sizing to content.
Sorry, I'm probably thick here ;)
@grokys so here it what happen precisely, whichever the value of SizeToContent.
ClientSize OR by triggering a stackpanel to become visible which should change the size of the window if SizeToContent is set to Width/Height)What I noticed was that after step 3. the windows ClientSize and DesiredSize is what is expected.
But as soon as 4. happen, the size go back to 800x600.
My workaround is to have a DispatcherTimer which look my viewmodel every second and resize to a fixed hardcoded size. Not pretty... but good enough for me. :p
What is the content of your StackPanel? Does it have a fixed size? SizeToContent only works if your content has a fixed size (DesiredSize != infinity)
@Gillibald here is my windows:
https://github.com/btcpayserver/BTCPayServer.Vault/blob/master/BTCPayServer.Vault/MainWindow.xaml
The problematic stackpanel is <StackPanel IsVisible="{Binding IsVisible}" Margin="0,15,0,0">
SizeToContent is actually unrelated to this issue. The same problem happen if it is in Manual.
I am sorry, just updated the description. I noticed it was unrelated to SizeToContent only later after posting.
Most helpful comment
I tried to solve this here https://github.com/AvaloniaUI/Avalonia/pull/2383 but gave up... The description only mentions X11, but this was also an attempt to fix auto-resizing on other platforms too. Unfortunately I think my solution was flawed. Probably need to revisit this soon.
@jmacato I don't think this can be fixed for 0.9, it's not a simple problem.