dotnet: Existence of SizeToContent in XAML breaks Loaded Event of window
SizeToContentProblem.zip
We’ve noticed a very strange behaviour that is reproducible in VS 2017 and with dotnet 4.6.2.
The attached repro case consist of a window with a button that opens another window. In this window there is an interactivity trigger (TestWindow.xaml) that should create a message box and a console entry.
However due to the presence of SizeToContent="Height" in the very same xaml, dotnet does only emit the console write line from the callback set in the code behind (Loaded="TestWindow_OnLoaded") but ignores the callback that should be executed in TestWindowViewModel.
If the SizeToContent attribute is removed in TestWindow.xaml, then the expected message box is displayed and the second console output (after the message box) is generated, see the image below for the correct version when SizeToContent is commented out.

About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 22 (3 by maintainers)
We recently upgraded our WPF projects to target .NET 4.7.1 so I tried to remove the workaround mentioned in the StackOverflow post linked by @Bodewes as @SirRufo mentioned he was not able to reproduce the issue on .NET 4.7.1
It still did not execute the command. Just to confirm that I didn’t screw up, I removed the SizeToContent=“WidthAndHeight” and tried again. This time the command was executed as you would expect.
Windows 10 1709.16299.248 VS2017 15.5.4
please reopen - still not fixed
VS2022 17.6.0 .Net7
It is still not fixed.
Here’s a simple repro app using .NET 8.
WpfLoadedEventTest.zip
I noticed your repro app uses the community MVVM toolkit. I wonder if it does something as a workaround for this issue? My repro app does not use any packages other than Microsoft.Xaml.Behaviors.Wpf.
This also happens on VS 2019 and .Net 4.8 - Any workarounds/recommendations?