How do I bind from XXXContextContentTemplate to related DockingWindow?

Docking/MDI for WPF Forum

Posted 8 years ago by Markus Springweiler
Version: 16.1.0631
Avatar

Is there any attached property I can bind to? The visual tree seems to be totally unrelated so there is no parent container I can search for via RelativeSource.

 

Concrete problem: I have to reference an attached property on DocumentWindow from within the DataTemplate assigned to TabbedMdiTabContextContentTemplate.

[Modified 8 years ago]

Comments (3)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Markus,

Right, the relative source won't work since an AdvancedTabControl instance is housing that tab within the TabbedMdiContainer's template, and each tab is generated with the DockingWindow as an "item".  The contextual content DataTemplates are presented using a ContentPresenter within the AdvancedTabItem.  When developing vNext, we used to pass the DockingWindow as Content to the contextual ContentPresenter, but ran into logical tree issue due to the parent tab also having the DockingWindow as Content.  Thus we now pass the DockingWindow.DataContext as long as it's not a UIElement.

So you can pass an object in the DockingWindow.DataContext with any info you need to pass to your contextual DataTemplate.  Just make sure the DataContext object isn't a UIElement.  But it can be any other object that wraps properties on your main DockingWindow.


Actipro Software Support

Posted 8 years ago by Markus Springweiler
Avatar

I was in hope for a generic way to reach the according DockingWindow. Using the last version I had one global style targetting ToolWindow which set a HeaderTemplate which consumed an attached property of the ToolWindow (without any special coding since the attached properted is inheritable) and additionally the description of the ToolWindow by the use of this Binding:


{Binding RelativeSource={RelativeSource AncestorType={x:Type docking:IDockingWindowProvider}}, Path=(docking:IDockingWindowProvider.DockingWindow).Description}

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Markus,

If you aren't using MVVM, you can set up your DockingWindow.DataContext to be a WeakReference to the DockingWindow, like this in a DockSite.WindowRegistered event:

private void DockSite_WindowRegistered(object sender, DockingWindowEventArgs e) {
	e.Window.DataContext = new WeakReference(e.Window);
}

Then have this kind of thing in your contextual context DataTemplate:

<TextBlock Text="{Binding Target.Title}" FontStyle="Italic" />


Actipro Software Support

The latest build of this product (v24.1.3) was released 28 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.