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

拜拜、爱过 提交于 2019-11-28 11:07:09
Martin

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.

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