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

断了今生、忘了曾经 提交于 2019-11-27 05:59:35

问题


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).

回答1:


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.



来源:https://stackoverflow.com/questions/23406451/sample-code-to-show-how-to-use-avalondock-in-an-mvvm-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!