private void UnfloatItemExecuted(object _) { var dockItem = _ as DockItem; if (dockItem == null) { return; } var executingDockControl = this.GetVisualChildren().OfType <DockControl>(). FirstOrDefault(t => t.InterTabController != null && t.InterTabController.Partition == Partition); if (executingDockControl == null) { return; } var newTabHost = executingDockControl.InterTabController.InterTabClient.GetNewHost( executingDockControl.InterTabController.InterTabClient, executingDockControl.InterTabController.Partition, executingDockControl); if (newTabHost?.DockControl == null || newTabHost.Container == null) { throw new ApplicationException("New tab host was not correctly provided"); } var floatingItemSnapShots = dockItem.GetVisualChildren() .OfType <Layout>() .SelectMany(l => l.FloatingDockItems().Select(FloatingItemSnapShot.Take)) .ToList(); var content = dockItem.Content ?? dockItem; FloatingItems.Remove(content); var window = this.GetVisualAncestors().OfType <Window>().FirstOrDefault(); if (window == null) { throw new ApplicationException("Unable to find owning window."); } newTabHost.Container.Width = window.Width; newTabHost.Container.Height = window.Height; Dispatcher.UIThread.InvokeAsync(new Action(() => { newTabHost.DockControl.AddToSource(content); newTabHost.DockControl.SelectedItem = content; newTabHost.Container.Show(); newTabHost.Container.Activate(); Dispatcher.UIThread.InvokeAsync( new Action(() => RestoreFloatingItemSnapShots(newTabHost.DockControl, floatingItemSnapShots))); }), DispatcherPriority.DataBind); }
private void UnfloatExecuted(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs) { var dragablzItem = executedRoutedEventArgs.Parameter as DragablzItem; if (dragablzItem == null) { return; } var containsBranch = this.LogicalTreeDepthFirstTraversal().OfType <Branch>().Any(); var exemplarTab = containsBranch //use Visual Traversal when branches exist ? this.VisualTreeDepthFirstTraversal().OfType <TabablzControl>() .FirstOrDefault(t => t.InterTabController != null && t.InterTabController.Partition == Partition) : this.LogicalTreeDepthFirstTraversal().OfType <TabablzControl>() .FirstOrDefault(t => t.InterTabController != null && t.InterTabController.Partition == Partition); if (exemplarTab == null) { return; } //TODO passing the exemplar tab in here isnt ideal, as strictly speaking there isnt one. var newTabHost = exemplarTab.InterTabController.InterTabClient.GetNewHost(exemplarTab.InterTabController.InterTabClient, exemplarTab.InterTabController.Partition, exemplarTab); if (newTabHost == null || newTabHost.TabablzControl == null || newTabHost.Container == null) { throw new ApplicationException("New tab host was not correctly provided"); } var content = dragablzItem.Content ?? dragablzItem; //remove from source CollectionTeaser collectionTeaser; if (CollectionTeaser.TryCreate(FloatingItemsSource, out collectionTeaser)) { collectionTeaser.Remove(content); } else { FloatingItems.Remove(content); } var myWindow = Window.GetWindow(this); if (myWindow == null) { throw new ApplicationException("Unable to find owning window."); } newTabHost.Container.Width = myWindow.RestoreBounds.Width; newTabHost.Container.Height = myWindow.RestoreBounds.Height; newTabHost.Container.Left = myWindow.Left + 20; newTabHost.Container.Top = myWindow.Top + 20; Dispatcher.BeginInvoke(new Action(() => { newTabHost.TabablzControl.AddToSource(content); newTabHost.TabablzControl.SelectedItem = content; newTabHost.Container.Show(); newTabHost.Container.Activate(); }), DispatcherPriority.DataBind); }