I am working on upgrading our application from version 2015 to 2019. I have it running, but working through some details with Docking. We are using MVVM pattern. We have a DockSite defined like:
<docking:DockSite DocumentItemsSource="{Binding Tabs}" AreNewTabsInsertedBeforeExistingTabs="False"
DocumentItemContainerStyle="{StaticResource DocumentItemStyle}">
<docking:Workspace>
<docking:TabbedMdiHost/>
</docking:Workspace>
</docking:DockSite>
The Tabs collection is an ObservableCollection of a class similar to:
public class DockItem : ContentControl, INotifyPropertyChanged
{
public IViewModel ViewModel { get; set; }
// other public properties for Header, Title, IsActive, IsSelected, ImageToShow, etc.
}
When we add items to the Tabs collection, that show as expected in the DockSite. My current issue is that I am trying to get the "tab title" to display how it used to when we were using the Header and HeaderTemplate in our DocumentItemStyle style. I understand from the documentation I can use a DataTemplate for the TabbedMdiTabContextContentTemplate property on the DockingWindow. I am struggling, however, to get the elements in the template to acces properties on our DockItem class of the tab. The documentation says:
The data context of the DataTemplate will be the DataContext of the docking window, unless the DataContext is a UIElement. In that case, no data context is passed since it could otherwise lead to logical tree issues.
I'm assuming my issue is due to our DockItem class deriving from ContentControl so "no data context is passed...".
My template has:
<Style x:Key="DockingItemStyle" TargetType="docking:DockingWindow" >
<Setter Property="Title" Value="{Binding Header}" />
<Setter Property="TabbedMdiTabContextContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Header}" />
<Image Source="{Binding ImageToShow}" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Is there any way for the bindings in the DataTemplate to either access the DockItem class properties or the DocumentWindow properties?
I have looked at the sample to get some ideas to try but would like have to make some large changes to how we have done some things; so hoping for an easier option.
[Modified 5 years ago]