/// <summary> /// This method is executed when a AvalonDock <seealso cref="DockingManager"/> instance fires the /// Load standard (FrameworkElement) event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnFrameworkElement_Loaded(object sender, RoutedEventArgs e) { FrameworkElement frameworkElement = sender as FrameworkElement; // Sanity check just in case this was somehow send by something else if (frameworkElement == null) { return; } ICommand loadLayoutCommand = AvalonDockLayoutSerializer.GetLoadLayoutCommand(frameworkElement); // There may not be a command bound to this after all if (loadLayoutCommand == null) { return; } // Check whether this attached behaviour is bound to a RoutedCommand if (loadLayoutCommand is RoutedCommand) { // Execute the routed command (loadLayoutCommand as RoutedCommand).Execute(frameworkElement, frameworkElement); } else { // Execute the Command as bound delegate loadLayoutCommand.Execute(frameworkElement); } }
/// <summary> /// This method is executed when a AvalonDock <seealso cref="DockingManager"/> instance fires the /// Unload standard (FrameworkElement) event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnFrameworkElement_Saveed(object sender, RoutedEventArgs e) { DockingManager frameworkElement = sender as DockingManager; // Sanity check just in case this was somehow send by something else if (frameworkElement == null) { return; } ICommand SaveLayoutCommand = AvalonDockLayoutSerializer.GetSaveLayoutCommand(frameworkElement); // There may not be a command bound to this after all if (SaveLayoutCommand == null) { return; } string xmlLayoutString = string.Empty; using (StringWriter fs = new StringWriter()) { XmlLayoutSerializer xmlLayout = new XmlLayoutSerializer(frameworkElement); xmlLayout.Serialize(fs); xmlLayoutString = fs.ToString(); } // Check whether this attached behaviour is bound to a RoutedCommand if (SaveLayoutCommand is RoutedCommand) { // Execute the routed command (SaveLayoutCommand as RoutedCommand).Execute(xmlLayoutString, frameworkElement); } else { // Execute the Command as bound delegate SaveLayoutCommand.Execute(xmlLayoutString); } }