演示如何在MVVM应用程序中使用Avalondock的示例代码。

时间:2021-09-09 00:24:17

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.

我正在尝试在我的wpf应用程序中使用AvalonDock,这是一个MVVM应用程序。环顾四周,我找不到任何示例应用程序来说明我如何做到这一点。

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

AlavonDock说它对MVVM有本地支持,所以支持MVVM应该很容易,但是没有示例代码。

My questions are:

我的问题是:

  1. How to write xaml that has a document manager and it is binded to viewmodel?
  2. 如何编写具有文档管理器且绑定到viewmodel的xaml ?
  3. How to add a new document to panel in this scenario?
  4. 如何在此场景中向面板添加新文档?
  5. How can I get information about layout from documentmanegr (if it is possible).
  6. 如何从documentmanegr获取布局信息(如果可能)。

2 个解决方案

#1


12  

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

在AvalonDock的CodePlex源代码中有一个例子——它不包括在正常的下载中。您需要进入源代码控制页面并单击“下载”。

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.

此外,我还编写了一个示例应用程序,您也可以使用它入门,我写了一篇简短的博客文章来描述它,并将其放到GitHub上。

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

基本上,您可以设置LayoutItemContainerStyle来消除视图和视图模型之间的差异,例如:

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

在本例中,DockManagerViewModel有一个属性“Documents”,其中包含一个viewmodel集合,其中包含标题、CloseCommand和CanClose属性。

#2


2  

I think this is what you need
Code Project - Avalon tutorial

我认为这就是您需要的代码项目——Avalon教程。

#1


12  

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

在AvalonDock的CodePlex源代码中有一个例子——它不包括在正常的下载中。您需要进入源代码控制页面并单击“下载”。

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.

此外,我还编写了一个示例应用程序,您也可以使用它入门,我写了一篇简短的博客文章来描述它,并将其放到GitHub上。

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

基本上,您可以设置LayoutItemContainerStyle来消除视图和视图模型之间的差异,例如:

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

在本例中,DockManagerViewModel有一个属性“Documents”,其中包含一个viewmodel集合,其中包含标题、CloseCommand和CanClose属性。

#2


2  

I think this is what you need
Code Project - Avalon tutorial

我认为这就是您需要的代码项目——Avalon教程。