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

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

问题描述

我想在我的WPF应用程序这是一个MVVM应用程序使用AvalonDock。我看周围也找不到我展示如何做到这一点的示例应用程序。



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



我的问题是:




  1. 如何写一个具有文档管理器XAML和它绑定到
    视图模型?

  2. 如何在这种情况下一个新文档添加到面板?

  3. 如何获取有关documentmanegr布局信息(如果可能)。


解决方案

有一个示例应用程序在AvalonDock的CodePlex网站源代码 - 它不包括在正常下载。你需要去 https://avalondock.codeplex.com/SourceControl/latest# 并点击下载。



此外,我写了一个示例应用程序,你也可以用上手,我写了一个快速的博客文章描述它(的http://lostindetails.com/blog/post/AvalonDock-2.0-with-MVVM ),并把它放在GitHub上(计算器阻止我张贴的链接,由于信誉的限制,它在博客文章)



基本上,你可以设置LayoutItemContainerStyle缩小视图之间的差距,您的视图模型,例如:

 <窗口... 
的xmlns:码头=HTTP://模式.xceed.com / WPF / XAML / avalondock
的xmlns:dockctrl =CLR的命名空间:Xceed.Wpf.AvalonDock.Controls;装配= Xceed.Wpf.AvalonDock
>

<码头:DockingManager的DataContext ={结合DockManagerViewModel}
DocumentsSource ={约束力的文件}>

<码头:DockingManager.LayoutItemContainerStyle>
<! - 你可以从layoutitem到DockWindowViewModel添加额外的绑定 - >
<风格的TargetType ={X:类型dockctrl:LayoutItem}>
< setter属性=标题VALUE ={结合Model.Title}/>
< setter属性=CloseCommandVALUE ={结合Model.CloseCommand}/>
< setter属性=CanCloseVALUE ={结合Model.CanClose}/>
< /样式和GT;
< /码头:DockingManager.LayoutItemContainerStyle>

< /码头:DockingManager>

< /窗GT;

在这个例子中,DockManagerViewModel与有标题的ViewModels的集合属性'文件', 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 https://avalondock.codeplex.com/SourceControl/latest# 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 (http://lostindetails.com/blog/post/AvalonDock-2.0-with-MVVM) and put it on github (stackoverflow prevents me from posting the link due to reputation restrictions, it's in the blog post)

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.

Take care,
Martin

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

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