Avalondock MVVM布局 [英] Avalondock MVVM Layout

查看:97
本文介绍了Avalondock MVVM布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在>之前没有被问到我没有办法回答喜欢

我知道如何使用XAML中的LayoutAnchorablePaneGroupLayoutAnchorablePaneLayoutDocument创建要达到的布局,但是我想以MVVM方式使用Avalondock,从而将XAML减少为:

I know how to create the Layout I want to achive, using LayoutAnchorablePaneGroup, LayoutAnchorablePane and LayoutDocument in XAML, but I wanted to use Avalondock in a MVVM way, reducing my XAML to:

<avalonDock:DockingManager x:Name="dockingManager" 
                                       DataContext="{Binding DockManagerViewModel}"
                                       DocumentsSource="{Binding Documents}"
                                       AnchorablesSource="{Binding Anchorables}"
                                       Loaded="dockingManager_Loaded" 
                                       Unloaded="dockingManager_Unloaded">

填充DocumentsAnchorables会使所需的窗口出现在dockingManager中,但是我看不到如何确定它们出现的位置.

Filling the Documents and Anchorables makes the desired windows appear in the dockingManager, but I don't see how I can secify the location in which they will appear.

如何在不失去MVVM分隔的情况下指定一些规则(以前在XAML中)以构建特定的布局?

How can I specify some rules ( prefferably in XAML ), to build a specific Layout, without loosing the MVVM separation?

E.G .:类型A的对象都应该放在右侧的LayoutAnchorablePane中,类型B的对象都应该放在左侧的LayoutAnchorablePane中,等等.

E.G.: objects of Type A should all go togehter in a LayoutAnchorablePane on the right, Objects of type B all go together in a LayoutAnchorablePane on the left etc..

谢谢.

推荐答案

我也遇到了同样的情况.并找到了一个棘手但对我有用的解决方案.

I went to the same situation. and found a solution which is tricky but works for me.

遵循代码项目解决方案,并隐式保存和加载布局.

Followed the Solution on Code Project and implimented save and load the layout.

请注意,在应用程序首次启动时,它没有布局,因此您需要使用所需的布局创建XML,然后再加载已保存的布局.希望这可以帮助.

note that for the first time when the application starts it does not have the layout so you need to create a XML with your desired layout and later on you can load the saved layout. hope this helps.

停靠管理器示例:

  <xcad:DockingManager x:Name="DockingManagerDockView"
                         AnchorablesSource="{Binding AnchorableSource}" 
                         DocumentsSource="{Binding DocumentSource}" 
                         Utility:AvalonDockLayoutSerializer.SaveLayoutCommand="{Binding SaveLayoutCommandOnExit}"
                         Utility:AvalonDockLayoutSerializer.LoadLayoutCommand="{Binding LoadLayoutCommand}">       
    <xcad:DockingManager.Theme>
        <xcad:MetroTheme />
    </xcad:DockingManager.Theme>
    <xcad:DockingManager.LayoutUpdateStrategy>
        <Pane:LayoutInitializer/>
    </xcad:DockingManager.LayoutUpdateStrategy>
    <xcad:DockingManager.Resources>            
        <DataTemplate DataType="{x:Type ViewModels:ExplorerViewModel}">
            <Views:ExplorerView />
        </DataTemplate>            
        <DataTemplate DataType="{x:Type ViewModels:TableOfContentViewModel}">
            <Views:TableOfContentView x:Name="TOCView" Focusable="True">
                <Views:TableOfContentView.InputBindings>
                    <KeyBinding Key="F5" Command="{Binding GridF5Command}"/>
                </Views:TableOfContentView.InputBindings>
            </Views:TableOfContentView>
        </DataTemplate>
        <DataTemplate DataType="{x:Type ViewModels:PropertyViewModel}">
            <Views:PropertyView />
        </DataTemplate>           
        <DataTemplate DataType="{x:Type ViewModels:SearchViewModel}">
            <Views:SearchPanel />
        </DataTemplate>
        <DataTemplate DataType="{x:Type ViewModels:DocumentViewModel}">
            <Views:DocumentView />
        </DataTemplate>
        <DataTemplate DataType="{x:Type ViewModels:ReIndexPanelViewModel}">
            <Views:ReIndexPanel />
        </DataTemplate>
    </xcad:DockingManager.Resources>       
    <xcad:DockingManager.LayoutItemContainerStyleSelector>
        <Pane:PanesStyleSelector>
            <Pane:PanesStyleSelector.ToolStyle>
                <Style TargetType="{x:Type xcad:LayoutAnchorableItem}">
                    <Setter Property="Title" Value="{Binding Model.Title}"/>
                    <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/>
                    <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                    <Setter Property="FlowDirection" Value="LeftToRight"/>
                    <Setter Property="UseLayoutRounding" Value="False"/>
                    <Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
                </Style>
            </Pane:PanesStyleSelector.ToolStyle>
            <Pane:PanesStyleSelector.FileStyle>
                <Style TargetType="{x:Type xcad:LayoutItem}">
                    <Setter Property="Title" Value="{Binding Model.Title}"/>
                    <Setter Property="ToolTip" Value="{Binding Model.FilePath}"/>
                    <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                    <Setter Property="CanClose" Value="False"/>                        
                </Style>
            </Pane:PanesStyleSelector.FileStyle>
        </Pane:PanesStyleSelector>
    </xcad:DockingManager.LayoutItemContainerStyleSelector>
    <xcad:LayoutRoot>
        <xcad:LayoutPanel Orientation="Horizontal">                
                <xcad:LayoutAnchorablePaneGroup>
                    <xcad:LayoutAnchorablePane Name="Explorer" DockMinWidth="250"/> 
                    <xcad:LayoutAnchorablePane Name="TOC" DockMinWidth="500"/>
                    <xcad:LayoutAnchorablePane Name="Property" DockMinWidth="300" />
                    <xcad:LayoutAnchorablePane Name="Search" DockMinWidth="300" />
                    <xcad:LayoutAnchorablePane Name="ReIndex" DockMinHeight="300" />
                </xcad:LayoutAnchorablePaneGroup>
            <xcad:LayoutDocumentPaneGroup >
                <xcad:LayoutDocumentPane/>
            </xcad:LayoutDocumentPaneGroup>
        </xcad:LayoutPanel>            
    </xcad:LayoutRoot>
</xcad:DockingManager>

这篇关于Avalondock MVVM布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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