/// <summary> /// Occurs when a docking window's default location is requested. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">The <c>DockingWindowDefaultLocationEventArgs</c> that contains data related to this event.</param> private void OnDockSiteWindowDefaultLocationRequested(object sender, DockingWindowDefaultLocationEventArgs e) { if (!this.IsDockingWindowAValidContainer(e)) { return; } // Get the region var region = this.Region; if (region == null) { return; } var viewModel = e.Window.DataContext as ToolItemViewModel; if (viewModel != null) { // Get the dock state var dockState = (ToolItemState) new ToolItemStateConverter().Convert(e.State, typeof(ToolItemState), null, null); // Query the tool view-model for default locations relative to other tool view-models var defaultLocations = viewModel.GetDefaultLocations(dockState); if (defaultLocations != null) { foreach (var defaultLocation in defaultLocations) { if ((defaultLocation != null) && (!string.IsNullOrEmpty(defaultLocation.TargetSerializationId))) { var targetViewModel = region.Views.OfType <ToolItemViewModel>().FirstOrDefault(vm => vm.SerializationId == defaultLocation.TargetSerializationId); if ((targetViewModel != null) && (targetViewModel.IsOpen)) { // Another open tool view-model was located var targetWindow = dockSite.ContainerFromItem(targetViewModel); if (targetWindow != null) { e.Target = targetWindow; e.Side = (Side) new ToolItemDockSideConverter().ConvertBack(defaultLocation.DockSide, typeof(Side), null, null); return; } } } } } } }