2016-02-08 80 views
3

所以这个问题已经被问过but not answerednot answered the way I would likeAvalondock MVVM布局

我知道如何创建我想才达到的布局,使用LayoutAnchorablePaneGroupLayoutAnchorablePane和XAML LayoutDocument,但我想在MVVM使用Avalondock这样,减少了我的XAML到:

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

灌装DocumentsAnchorables使所需的窗口出现在dockingManager,但我不知道怎样才能secify,他们将出现的位置。

如何在不丢失MVVM分隔的情况下指定一些规则(预先在XAML中)来构建特定布局? A型的

例如为:对象应该都去togehter在LayoutAnchorablePane右侧,B类型的对象都去一起在左边一个等.. LayoutAnchorablePane提前

感谢。

+0

这是一个相当宽泛的问题和一些除了那些你报价,喜欢http://stackoverflow.com/a/32567244/2224701答案,或http:/ /www.codeproject.com/Articles/239342/AvalonDock-and-MVVM –

+0

是的,我见过这些。链接1对于学习一般的Avalondock MVVM方法非常有用,但它并没有回答我的问题(或者我不明白答案),而我不确定链接2是否仍然相关。由于它没有使用'DataContext','DocumentSource'或'AnchorablesSoruce',它可能是一个拐杖,使旧的Avalondock版本与MVVM兼容。我希望使用AvalonDock 2.0可能会更容易一些。 –

+0

因此,您是否已经遵循了CodePlex AvalonDock MVVM示例应用程序方法,并且遇到了Anchorables的一些特定问题? “但我不明白我怎样才能确定他们出现的地点” - “地点”究竟意味着什么?你需要实现一些特定的初始布局?考虑让你的问题更具体。 –

回答

0

我去过同样的情况。并找到了一个棘手但适合我的解决方案。

跟着Solution on Code Project实现保存并加载布局。

请注意,第一次应用程序启动时,它没有布局,因此您需要创建一个带有所需布局的XML,稍后可以加载保存的布局。希望这可以帮助。

例对接经理:

<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> 
+0

是的,我已经看到了这个,但是我对这个解决方案有一个问题:如果您添加一个新文档,您如何指定它应该在哪个DocumentPane中创建? –

+0

对不起,想创建新行,输入添加评论:) –

+0

好吧,很好,我已经添加了如何我的对接管理器是如何做到的答案。 –