
Hi Miles,
Yes, here's a very small example that works with v2016.1. XAML for a MainControl:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ToolBar DockPanel.Dock="Top">
<Button Content="Open" Command="Open" />
</ToolBar>
<!-- DockSite -->
<sample:CustomDockSite x:Name="dockSite" Grid.Row="1">
<docking:SplitContainer>
<docking:Workspace>
<docking:TabbedMdiHost />
</docking:Workspace>
<docking:ToolWindowContainer>
<docking:ToolWindow Title="Solution Explorer">
<DockPanel>
<ToolBar DockPanel.Dock="Top">
<Button Content="Open" Command="Open" />
</ToolBar>
<TextBox BorderThickness="0" />
</DockPanel>
</docking:ToolWindow>
</docking:ToolWindowContainer>
</docking:SplitContainer>
</sample:CustomDockSite>
</Grid>
Code-behind for MainControl:
public partial class MainControl {
public MainControl() {
InitializeComponent();
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, OnOpenCommandExecuted));
}
private void OnOpenCommandExecuted(object sender, ExecutedRoutedEventArgs e) {
MessageBox.Show("Open dialog here");
}
}
CustomDockSite class:
public class CustomDockSite : DockSite {
private void CopyCommandBindings(UIElement source, Window target) {
if ((source != null) && (target != null)) {
foreach (CommandBinding binding in source.CommandBindings)
target.CommandBindings.Add(binding);
}
}
protected override void InitializeFloatingWindow(Window window) {
base.InitializeFloatingWindow(window);
// Get the ancestor control with all the command bindings
var bindingSource = VisualTreeHelperExtended.GetAncestor<MainControl>(this);
// Copy the bindings to the new Window
this.CopyCommandBindings(bindingSource, window);
}
}
The MainControl is where we define all our routed command bindings. In your app, you might need to adjust that logic or even the CopyCommandBindings logic as appropriate to suit your needs.
If you are using v2015.1 or older, you would need to replace InitializeFloatingWindow with CreateRaftingWindow, call the base method to get the Window that is created and pass that to the CopyCommandBindings method.