private void CopyPropertyChangesHandler(object sender, ExecutedRoutedEventArgs e) { if (this.currentSelection != null) { SaveEditedProperties(this.currentSelection); } EditedPropertiesHelper.DumpObjectsWithEditedProperties(); }
/// <summary> /// Loop through the properties in the current PropertyGrid and save away any properties /// that have been changed by the user. /// </summary> /// <param name="owningObject">currently selected object that owns the properties in the grid (before changing selection to the new object)</param> private void SaveEditedProperties(VisualTreeItem owningObject) { foreach (PropertyInformation property in PropertyGrid.PropertyGrid.Properties) { if (property.IsValueChangedByUser) { EditedPropertiesHelper.AddEditedProperty(Dispatcher, owningObject, property); } } }
/// <summary> /// Cleanup when closing the window. /// </summary> protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); // unsubscribe to owner window closing event // replaces previous attempts to hookup to MainWindow.Closing on the wrong dispatcher thread // This one should be running on the right dispatcher thread since this SnoopUI instance // is wired up to the dispatcher thread/window that it owns if (Owner != null) { Owner.Closing -= SnoopedWindowClosingHandler; } this.CurrentSelection = null; InputManager.Current.PreProcessInput -= this.HandlePreProcessInput; EventsListener.Stop(); EditedPropertiesHelper.DumpObjectsWithEditedProperties(); // 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); }
/// <summary> /// Event handler for a snooped window closing. This is our chance to spit out /// all the properties that changed during the snoop session for that window. /// Note: there may be multiple snooped windows (when in multiple dispatcher mode) /// and each window is hooked up to it's own instance of SnoopUI and this event. /// </summary> private void SnoopedWindowClosingHandler(object sender, CancelEventArgs e) { // changing the selection captures any changes in the selected item at the time of window closing this.CurrentSelection = null; EditedPropertiesHelper.DumpObjectsWithEditedProperties(); }