Search code examples
c#wpfmvvmuser-controlsavalondock

How to create new custom View(UserControl)? AvalonDock


I use the perfect library AvalonDock and I notice that Text Document is created when clicking "File->New" in the run program. However, I would like to create not Text Document, but some UserControl with my buttons and its viewmodel.

I've found a code creating new text documents:

private void OnNew(object parameter)
{
   _files.Add(new FileViewModel());
   ActiveDocument = _files.Last();
}

Now: enter image description here

Want to implement: enter image description here

This code creates TextDocument Is it possible? Do you have some tutorial how to implement it?

My questions is how to create UserControl instead of Text document with ViewModel?


Solution

  • It was really simple. If I replace TextBox in DataTemplate by UserControl called SomeUserControl, it is really replaced by UserControl and I can insert any controls:

    <Window x:Class="AvalonDock.MVVMTestApp.NewWindow"
        ....
        xmlns:local="clr-namespace:AvalonDock.MVVMTestApp">
    
      <avalonDock:DockingManager.LayoutItemTemplateSelector>
        <local:PanesTemplateSelector>
          <local:PanesTemplateSelector.FileViewTemplate>
            <DataTemplate>
               <!--<TextBox Text="{Binding TextContent, UpdateSourceTrigger=PropertyChanged}"/>-->            
               <local:SomeUserControl/>
            </DataTemplate>
          </local:PanesTemplateSelector.FileViewTemplate>      
        .....                               
      </avalonDock:DockingManager.LayoutItemTemplateSelector>
    </Window>
    

    AvalonDock is really cool docking windows control!