Created
February 24, 2020 03:31
-
-
Save nocd5/759df3ec27f69a17e80fd43d8317e869 to your computer and use it in GitHub Desktop.
Dragablz Custom InterTabClient for Caliburn.Micro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Caliburn.Micro; | |
using Dragablz; | |
using CaliburnApp.ViewModels; | |
using CaliburnApp.Views; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Windows; | |
using System.Windows.Threading; | |
using Action = System.Action; | |
namespace CaliburnApp | |
{ | |
public class InterTabClient : IInterTabClient | |
{ | |
public virtual INewTabHost<Window> GetNewHost(IInterTabClient interTabClient, object partition, TabablzControl source) | |
{ | |
if (source == null) throw new ArgumentNullException("source"); | |
var sourceWindow = Window.GetWindow(source); | |
if (sourceWindow == null) throw new ApplicationException("Unable to ascertain source window."); | |
var newWindow = new MainWindowView(); | |
newWindow.InitializeComponent(); | |
var vm = IoC.Get<MainWindowViewModel>(); | |
ViewModelBinder.Bind(vm, newWindow, null); | |
newWindow.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.DataBind); | |
var newTabablzControl = newWindow.LogicalTreeDepthFirstTraversal().OfType<TabablzControl>().FirstOrDefault(); | |
if (newTabablzControl == null) throw new ApplicationException("Unable to ascertain tab control."); | |
if (newTabablzControl.ItemsSource == null) | |
newTabablzControl.Items.Clear(); | |
return new NewTabHost<Window>(newWindow, newTabablzControl); | |
} | |
public virtual TabEmptiedResponse TabEmptiedHandler(TabablzControl tabControl, Window window) | |
{ | |
return TabEmptiedResponse.CloseWindowOrLayoutBranch; | |
} | |
} | |
static class Extensions | |
{ | |
public static IEnumerable<object> LogicalTreeDepthFirstTraversal(this DependencyObject node) | |
{ | |
if (node == null) yield break; | |
yield return node; | |
foreach (var child in LogicalTreeHelper.GetChildren(node).OfType<DependencyObject>() | |
.SelectMany(depObj => depObj.LogicalTreeDepthFirstTraversal())) | |
yield return child; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dragablz:TabablzControl ConsolidateOrphanedItems="True"> | |
<dragablz:TabablzControl.InterTabController> | |
<dragablz:InterTabController InterTabClient="{Binding InterTabClient}" /> | |
</dragablz:TabablzControl.InterTabController> | |
</dragablz:TabablzControl> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment