Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sample code to show how to use Avalondock in an MVVM application [closed]

I am trying to use AvalonDock in my wpf application which is an MVVM application. Looking around I could not find any sample application showing how can I do this.

AlavonDock says that it has native support for MVVM, so it should be easy to support mvvm, but there is no sample code.

My questions are:

  1. How to write xaml that has a document manager and it is binded to viewmodel?
  2. How to add a new document to panel in this scenario?
  3. How can I get information about layout from documentmanegr (if it is possible).
like image 786
mans Avatar asked Jan 27 '26 12:01

mans


1 Answers

there is an Example App in the CodePlex Source of AvalonDock - it's not included in the normal download. You'll need to go to the Source Control page and click on 'Download'.

Additionally, I've written an example App, that you can also use to get started, I wrote a quick blog post describing it and put it on GitHub.

Basically, you can set the LayoutItemContainerStyle to bridge the gap between the View and your ViewModel, for example:

<Window ...
  xmlns:dock="http://schemas.xceed.com/wpf/xaml/avalondock"
  xmlns:dockctrl="clr-namespace:Xceed.Wpf.AvalonDock.Controls;assembly=Xceed.Wpf.AvalonDock"
  >
  ...
  <dock:DockingManager DataContext="{Binding DockManagerViewModel}"
                       DocumentsSource="{Binding Documents}" >

    <dock:DockingManager.LayoutItemContainerStyle>
      <!-- you can add additional bindings from the layoutitem to the DockWindowViewModel -->
      <Style TargetType="{x:Type dockctrl:LayoutItem}">
        <Setter Property="Title" Value="{Binding Model.Title}" />
        <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" />
        <Setter Property="CanClose" Value="{Binding Model.CanClose}" />
      </Style>
    </dock:DockingManager.LayoutItemContainerStyle>

  </dock:DockingManager>

</Window>

In this example, DockManagerViewModel has a property 'Documents' with a collection of ViewModels that have a Title, CloseCommand and CanClose property.

like image 104
Martin Avatar answered Jan 29 '26 03:01

Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!