I find out that the EventToCommand
for the Loaded-event is not working as expected if the Window.SizeToContent
attribute is set to WidthAndHeight
.
The Loaded-event seems to be fired correctly, but the EventToCommand.Command
property is bound AFTER the Loaded event is fired.
If SizeToContent
is Manual the Command will be bound BEFORE Loaded is fired and it works as expected.
Does anyone also have problems with this behavior and/or an explanation for this?
My workaround for now is to bind to the DataContext
of the window:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded" >
<command:EventToCommand Command="{Binding ElementName=window, Path=DataContext.LoadedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
来源:https://stackoverflow.com/questions/32627331/eventtocommand-for-loaded-event-not-working-as-expected-if-window-sizetocontent