Reputation: 5144
I have a window with interaction that should execute command when loaded:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding ActivateCommand}" />
</i:EventTrigger>
<i:EventTrigger EventName="Closed" >
<i:InvokeCommandAction Command="{Binding DeactivateCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
This is how it is used:
var loginVM = new Login();
var loginView = new Views.Login();
loginView.DataContext = loginVM;
loginView.ShowDialog();
When login view DataContext
(view model) is set through xaml using view model locator, the EventTrigger
works just fine and executes command on the VM.
However, if I set DataContext
(view model) from code like in example above, the command on the view model does not get executed!?
I can also confirm that Loaded
event is fired just before the window is shown, so after the DataContext
has been set in the example... so data context is set, event fires but for some reason the command is not being called.
Any other event besides Loaded
works flawlessly, so I am totally puzzled...
Upvotes: 1
Views: 1325
Reputation: 5144
OK, so I can confirm that this is a BUG, that occurs when you set SizeToContent
:
Existence of SizeToContent in XAML breaks Loaded Event of window https://github.com/Microsoft/dotnet/issues/429
EventToCommand for Loaded event not working as expected if Window.SizeToContent = WidthAndHeight
Upvotes: 3