AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.34k stars 2.2k forks source link

Possible bug? Actual window content depends on when `Show()` is called #12703

Closed BreyerW closed 1 year ago

BreyerW commented 1 year ago

Describe the bug Depending on the order of inserting childs and customizing appearance against Show() call can result in very different looking window

To Reproduce Steps to reproduce the behavior:

  1. Paste in blank avalonia project one of these snippets:
      var Item = new Window();
      Item.Show();
      Item.Content = //place any controls here
      Item.SizeToContent = SizeToContent.WidthAndHeight;

or

      var Item = new Window();
      Item.Content = //place any controls here
      Item.SizeToContent = SizeToContent.WidthAndHeight;
      Item.Show();
  1. Start project (need to do it twice, once for ech snippet
  2. Observe differences between actual window renderings

Expected behavior Both snippets should look the same

Screenshots

early Show() call in my project:

Zrzut ekranu (4)

late Show() call in my project:

Zrzut ekranu (3)

Note: these shots are from my actual project not from provided snippets, just to illustrate whats the problem. Both are exactly same data, exactly same steps to reproduce and exactly same code except for Show() call placement

Desktop (please complete the following information):

Tried to find duplicate, after 10 pages worth of open bugs i gave up sorry if it is already known.

emmauss commented 1 year ago

This isn't a bug, to my knowledge. When Show is called, the window is created and shown before Show returns, even if there's no content inside. This is valid behavior, as we can't defer showing the window until there's content. In both my tries using the current master, the first sample immediately resizes itself to the content after it's set. Does your content have a fixed/minimum size?

timunie commented 1 year ago

@BreyerW best if you can provide a very minimal sample

BreyerW commented 1 year ago

@emmauss actually its the 2nd sample that went haywire despite having content before Show() call. But after making clean project from reinstalled and newest templates i cant reproduce it either and on old project im unable to do it too buts thats after several commits. Must have been a bug in control layout/bindings on my part as i was experimenting heavily with ControlTheme for TabItem (TabControl, Grid and DockPanel with some dummy TextBoxes are practically the only controls i use currently for development). Didnt notice it since there were no errors and calling Show() early worked without issues which was weird. And just for the record i wasnt using Min/Max Width/Height, Window itself was used directly w/o XAML.

timunie commented 1 year ago

I'm closing this as it is not reproducible. Ping me if you found a way to reproduce.