Avalondock MVVM 布局
Avalondock MVVM Layout
所以这个问题在 but not answered or not answered the way I would like
之前已经被问过了
我知道如何创建我想要的布局,使用 LayoutAnchorablePaneGroup
、LayoutAnchorablePane
和 LayoutDocument
in XAML,但我想在MVVM 方式,将我的 XAML 减少为:
<avalonDock:DockingManager x:Name="dockingManager"
DataContext="{Binding DockManagerViewModel}"
DocumentsSource="{Binding Documents}"
AnchorablesSource="{Binding Anchorables}"
Loaded="dockingManager_Loaded"
Unloaded="dockingManager_Unloaded">
填充 Documents
和 Anchorables
使所需的 windows 出现在对接管理器中,但我不知道如何确定它们出现的位置。
我如何指定一些规则(最好在 XAML 中),以构建特定的布局,而不会失去 MVVM 分离?
例如:类型 A 的对象应该一起放在右边的 LayoutAnchorablePane
中,类型 B 的对象应该一起放在左边的 LayoutAnchorablePane
中,依此类推。
提前致谢。
我也遇到过同样的情况。并找到了一个棘手但对我有用的解决方案。
遵循 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>
所以这个问题在 but not answered or not answered the way I would like
之前已经被问过了我知道如何创建我想要的布局,使用 LayoutAnchorablePaneGroup
、LayoutAnchorablePane
和 LayoutDocument
in XAML,但我想在MVVM 方式,将我的 XAML 减少为:
<avalonDock:DockingManager x:Name="dockingManager"
DataContext="{Binding DockManagerViewModel}"
DocumentsSource="{Binding Documents}"
AnchorablesSource="{Binding Anchorables}"
Loaded="dockingManager_Loaded"
Unloaded="dockingManager_Unloaded">
填充 Documents
和 Anchorables
使所需的 windows 出现在对接管理器中,但我不知道如何确定它们出现的位置。
我如何指定一些规则(最好在 XAML 中),以构建特定的布局,而不会失去 MVVM 分离?
例如:类型 A 的对象应该一起放在右边的 LayoutAnchorablePane
中,类型 B 的对象应该一起放在左边的 LayoutAnchorablePane
中,依此类推。
提前致谢。
我也遇到过同样的情况。并找到了一个棘手但对我有用的解决方案。
遵循 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>