展示如何在 MVVM 应用程序中使用 Avalondock 的示例代码 [英] Sample code to show how to use Avalondock in an MVVM application

查看:22
本文介绍了展示如何在 MVVM 应用程序中使用 Avalondock 的示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 wpf 应用程序中使用 AvalonDock,该应用程序是一个 MVVM 应用程序.环顾四周,我找不到任何显示如何执行此操作的示例应用程序.

AlavonDock 说它原生支持 MVVM,所以支持 mvvm 应该很容易,但是没有示例代码.

我的问题是:

  1. 如何编写具有文档管理器并绑定到的xaml视图模型?
  2. 在这种情况下如何向面板添加新文档?
  3. 如何从 documentmanegr 获取有关布局的信息(如果可能).

解决方案

在 AvalonDock 的 CodePlex 源中有一个示例应用程序 - 它不包含在正常下载中.您需要转到源代码管理页面,然后点击下载".>

另外,我写了一个示例应用程序,你也可以用来开始,我写了一个 描述它的快速博客文章把它放在 GitHub 上.>

基本上,您可以设置 LayoutItemContainerStyle 来弥合 View 和您的 ViewModel 之间的差距,例如:

<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}"/></风格></dock:DockingManager.LayoutItemContainerStyle></dock:DockingManager></窗口>

在此示例中,DockManagerViewModel 有一个属性Documents",其中包含一组 ViewModel,这些 ViewModel 具有 Title、CloseCommand 和 CanClose 属性.

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

解决方案

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.

这篇关于展示如何在 MVVM 应用程序中使用 Avalondock 的示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆