Linking a LayoutDocument title from a collection in AvalonDock 2.0

I am binding the ObservableCollection to AvalonDock 2.0 where each item in the collection is an AvalonDock document. This is how I do the binding:

<ad:DockingManager DocumentsSource="{Binding Path=OpenProjects, Mode=TwoWay}" ActiveContent="{Binding Path=CurrentProject, Mode=TwoWay}" LayoutItemTemplateSelector="{StaticResource ProjectTemplateSelector}">
...
</ad:DockingManager>

      

The problem is that I want to show the name of each item (which is specified in the property Name

in CurrentProject

) as the title of the document. This is what I tried:

<ad:DockingManager.DocumentHeaderTemplate>
    <DataTemplate>
        <TextBlock DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ad:DockingManager}, Path=ActiveContent, Mode=OneWay}" Text="{Binding Path=Name}" />
    </DataTemplate>
</ad:DockingManager.DocumentHeaderTemplate>

      

This works great if I only have one document open, but when I have several, they all show the Name

current project. For example, if I have four open projects named "A", "B", "C" and "D", if I am currently viewing document "C", all four tabs will display the title "C", and when I go to document "B", they all change their names to "B".

Is there a way to prevent this change? I tried to set the binding mode to OneTime

but it doesn't work.

+3


source to share


2 answers


What I ended up with was as simple as:

<ad:DockingManager.DocumentHeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Content.Name}" />
    </DataTemplate>
</ad:DockingManager.DocumentHeaderTemplate>

      



Explanation: The DataContext for binding inside the DocumentHeaderTemplate is the LayoutDocument itself. It turns out it has a property called Content, which is a binding object inside every document (in this case, every project inside my OpenProjects collection). In this object, I have a Name property, which is the string that I want to use for the title.

+13


source


This is because you are binding the title text to a property of the object that is referenced by ActiveContent

your docking manager. Obviously changing ActiveContent

(focusing documents) will update the title of all views LayoutDocument

to the same value, since all titles are bound to the same origin.

You can try something like this:



<ad:DockingManager.DocumentHeaderTemplate>
    <DataTemplate>
        <Border x:Name="Header">
            <ad:AnchorablePaneTitle Model="{Binding Model, RelativeSource={RelativeSource TemplatedParent}}"/>
        </Border>
    </DataTemplate>
</ad:DockingManager.DocumentHeaderTemplate>

      

+3


source







All Articles