Dotnet: Existence of SizeToContent in XAML breaks Loaded Event of window

Created on 20 Jun 2017  路  11Comments  路  Source: microsoft/dotnet

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.

grafik

Most helpful comment

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

All 11 comments

I sent this to the WPF team. Thanks for reporting.

For Microsoft folks: I created Microsoft-internal VSTS bug 460315 to track this.

I tested with Win10 1709.16299.19, VS2017 v15.5.0 Preview 2.0, .net v4.7.02556 and there is no such issue. It seems to be fixed with the .net 4.7.1 update

Great!

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

I can confirm that this issue hasn't been fixed. Please find the attached example, targeting .NET 4.7.1, which demonstrates the problem very clearly. The command in the event trigger starts working as soon as the SizeToContent="WidthAndHeight" is removed.

SizeToContentProblem_NET471.zip

Confirmed, Even if you setSizeToContent="Width", Loaded event does not fired, starts working as soon as SizeToContent="Width" is Removed.

was trying below code.

<telerik:EventToCommandBehavior.EventBindings>            
            <telerik:EventBinding Command="{Binding OnLoadCommand}" EventName="Loaded"/>
</telerik:EventToCommandBehavior.EventBindings>

is it fixed yet? until june 19th 2019

Still not fix if SizeToContent="Width" .

VS2019 16.4.4
.NET Framework 4.7.2

This also happens on VS 2019 and .Net 4.8 - Any workarounds/recommendations?

Was this page helpful?
0 / 5 - 0 ratings