EventTrigger not firing for Loaded event of UserControl
mvvm, wpf
Solution
public MyUserControl()
{
DataContext = ServiceLocator.Current.GetInstance<DirectorySearchViewModel>();
InitializeComponent();
}
The Aristocrats.
Problem
I have a UserControl with the following event trigger: ``` <UserControl x:Class="TestApp.Views.MyUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" > <i:Interaction.Triggers> <i:EventTrigger EventName="Loaded"> <i:InvokeCommandAction Command="{Binding OnLoadedCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> ``` It is being set via the constructor of the UserControl (please ignore the ServiceLocator ..this is just a quick prototype): ``` public MyUserControl() { InitializeComponent(); DataContext = ServiceLocator.Current.GetInstance<DirectorySearchViewModel>(); } ``` In my view-model I have the following: ``` public ICommand OnLoadedCommand { get; private set; } public MyUserControl() { OnLoadedCommand = new DelegateCommand(OnLoaded); } public void OnLoaded() { } ``` OnLoaded never gets called. If I change the EventName to say ..MouseDown, then it works but it just won't work for Loaded Pretty sure it's a stupid mistake (swear I've done this a million times before in the past) but can't seem to figure it out right now