protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
this.CurrentSelection = null;
InputManager.Current.PreProcessInput -= this.HandlePreProcessInput;
EventsListener.Stop();
// persist the window placement details to the user settings.
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
IntPtr hwnd = new WindowInteropHelper(this).Handle;
Win32.GetWindowPlacement(hwnd, out wp);
Properties.Settings.Default.SnoopUIWindowPlacement = wp;
// persist whether all properties are shown by default
Properties.Settings.Default.ShowDefaults = this.PropertyGrid.ShowDefaults;
// persist whether the previewer is shown by default
Properties.Settings.Default.ShowPreviewer = this.PreviewArea.IsActive;
// actually do the persisting
Properties.Settings.Default.Save();
SnoopPartsRegistry.RemoveSnoopVisualTreeRoot(this);
}