0

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.

Rye bread
  • 1,305
  • 2
  • 13
  • 36
  • You should create a new data type that your DataTemplate can target e.g., `BlankTabItem` or `PlaceholderItem`. It should share a common interface or base class with the normal item model, so that you can host them in the same source collection. – BionicCode Sep 12 '22 at 12:10
  • Alternatively extend the DocumentManager to allow you to add a placeholder container explicitly. – BionicCode Sep 12 '22 at 12:13

1 Answers1

0

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.

Rye bread
  • 1,305
  • 2
  • 13
  • 36