Hello
There is no Closing or Closed event on a UserControl because it is a control/panel and placed along other controls.
But you may place your UserControl in a Silverlight ChildWindow control, which behaves like a Window in WPF. The ChildWindow has Closing and Closed events you can attach to when initiating and showing it.
If you want to log out when the Browser closes, there is a completely different approach. You will need to attach to the "Exit"-event on the application (App.xaml.cs).
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
InitializeComponent();
}
private void Application_Startup(object sender, StartupEventArgs e)
{
HtmlPage.RegisterScriptableObject("ShutdownManager", new ShutdownManager());
}
private void Application_Exit(object sender, EventArgs e)
{
}
If you need some service-calls also, you will need to use the "ScriptableType" to handle the browser's close event via JavaScript.
The "ScriptableType" is defined as a class I call "ShutdownManager":
[ScriptableType]
public class ShutdownManager
{
[ScriptableMember]
public Boolean CleanUp()
{
return true;
}
}
You call the "ShutdownManager" class in the Silverlight-project via JavaScript.
<body onbeforeunload="return doClose();"></body>
And here is the JavaScript function that is called:
function doClose() {
var plugin = document.getElementById('slcontrol');
var shutdownManager = plugin.content.ShutdownManager;
var cleanupResult = shutdownManager.CleanUp();
if (cleanupResult)
alert('You have been logged out!');
}
Hope that helps your problem!