Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fire Unload event of Usercontrol in a WPF window
    text
    copied!<p>I have an UserControl in WPF:</p> <pre><code>&lt;UserControl x:Class="XLogin.DBLogin" x:Name="DBLoginUserFrame" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" Height="263" Width="353" Loaded="DBLoginUserFrame_Loaded" Unloaded="DBLoginUserFrame_Unloaded"&gt; &lt;Grid&gt; &lt;GroupBox Header="Database Connection" HorizontalAlignment="Left" Height="243" Margin="10,10,0,0" VerticalAlignment="Top" Width="333"&gt; &lt;Grid&gt; &lt;TextBox x:Name="TextUserDB" HorizontalAlignment="Left" Height="20" Margin="101,60,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="173" /&gt; &lt;Label Content="Password:" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Width="70" HorizontalContentAlignment="Right" Margin="10,85,0,0" /&gt; &lt;PasswordBox x:Name="TextPasswordDB" HorizontalAlignment="Left" Height="20" Margin="101,89,0,0" VerticalAlignment="Top" Width="173" /&gt; &lt;Button x:Name="BtnConnect" Content="Connetti" Height="29" Width="123" Margin="101,152,97,24" Click="BtnConnect_Click" /&gt; &lt;/Grid&gt; &lt;/GroupBox&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>When i Unload this Control, WPF raise event <strong>DBLoginUserFrame_Unloaded</strong> that save my settings and it does a job.</p> <p>I have the MainWindow in WPF that load this user control but when window is closed, my usercontrol UNLOAD doesn't fire:</p> <pre><code>&lt;Window x:Class="XLogin.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:local="clr-namespace:XLogin" Unloaded="Window_Unloaded_1"&gt; &lt;Grid&gt; &lt;local:DBLogin/&gt; &lt;/Grid&gt;&lt;/Window&gt; </code></pre> <p><strong>How to add the UserControl Unload event to MainWindow event handler?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload