Add an extra tab item with a + character to an Xceed DockManager control

68 Views Asked by At

I am using Xceed.Wpf.AvalonDock to arrange views with a row of tabs along the top like in a WPF TabControl.

I am using it in an MVVM pattern like this:

<xcad:DockingManager Name="dock" DocumentsSource="{Binding VMs}" AllowMixedOrientation="True">
            <xcad:DockingManager.DocumentHeaderTemplate >
                <DataTemplate>
                    <!-- This defines the content of a single tab: -->
                    <StackPanel Orientation="Horizontal" MinWidth="100">
                        <Image Source="{Binding IconSource}" Margin="0,0,4,0"/>
                        <TextBlock Text="{Binding Title}" />
                    </StackPanel>
                </DataTemplate>
            </xcad:DockingManager.DocumentHeaderTemplate>

            <xcad:DockingManager.Resources>
                <DataTemplate DataType="{x:Type vm:MyViewModel}">
                    <v:MyView/>
                </DataTemplate>

Now I would like to add an extra tab at the top with a plus-character or similar, indicating to the user that they can add an extra tab / view by clicking on it. It would look similar to Chrome or Edge browsers.

How can I do that? Creating an empty view model and view just to receive clicks on the tab does not seem like a good way.

1

There are 1 best solutions below

0
Rye bread On

I ended up creating a special MenuVM and MenuView with a title property set to the '+' character. Then I added it to the VM collection as any other VM, but with some special handling, like disabling close etc.