Why user event loaded by user is not triggered

I have a user control. I had such situations again several times, but you could always fix it using the " New() contructor". But I'm still wondering what I'm doing wrong, because the load event should be fired if the control was loaded !

Here is the code:

 <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:my="clr-namespace:OUTPUT___VideoContent" Title="OUTPUT - VideoContent" Height="350" Width="525" Icon="/OUTPUT%20-%20VideoContent;component/Images/VideoContent.png"> <Grid x:Name="LayoutRoot"> <Grid x:Name="VideoGrid"> <my:ucVideoPresenter x:Name="VideoPresenter1"/> <TextBlock x:Name="txtInfo" Visibility="Collapsed" /> </Grid> </Grid> </Window> 

and in usercontrol, a load event is declared in WPF or code without any success! Usercontrol wpf

Usercontrol codebehind

+4
source share
2 answers

This is because an exception is thrown in the "Loaded" event handler. An exception can occur as a result of a mixed-mode assembly or some other exception that is "handled by the user" and the WPF infrastructure captures it (unknown to the debugger). This causes the debugger to not interrupt when a breakpoint is set in the Loaded method.

To make sure you see exactly what the error is:

  • In VS2010, go to Debug | Exceptions
  • Check the boxes with the exceptions "thrown" for the exceptions that may be applicable in your case.
  • Run the application again, and VS2010 should break the exception that is thrown in the event handler.
  • Debugging in accordance with the now famous exception.
+10
source

Does your UserControl constructor create an InitializeComponent() call without it, it will not create its visual effects, and the Loaded event may not fire.

+3
source

All Articles