I'm using Mvvm pattern and in View when the UserControl-Initialized event is binding to InitializedCommand as below.
<i:Interaction.Triggers>
<i:EventTrigger EventName="Initialized">
<prism:InvokeCommandAction Command="{Binding Path=InitializedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
and ViewModel as below.
public DelegateCommand InitializedCommand
{
get
{
SelectedPopupType = PopupTypes.Downloading;
IsShowPopup = true;
return new DelegateCommand(delegate ()
{
*** DoSomething...***
}
}
}
Other events(Loaded,Unloaded..) return parts are working properly but Initialized Command return does not work (DoSomething not called)..
I wonder whats the reason...
As the event name clearly says,
Initializedevent will get triggered before yourTriggerswere set via aAttachedProperty. WhereasLoadedevent will work, as it is triggered after all your property values were assigned and loaded. So, this won't work.Microsoft documentation says:
Also, why do you want to invoke a
ICommandfor aInitializedevent? Why can't you have aEventHandlerat your code-behind for this?