到目前为止,我主要使用Edi和AvalonDockMVVM来了解AvalonDock的工作原理,但都没有提供如何在我的应用程序中使用ILayoutUpdateStrategy的详细示例。
我的窗口的XAML看起来很像这样:
<avalonDock:DockingManager.LayoutItemTemplateSelector>
<pane:PanesTemplateSelector>
<pane:PanesTemplateSelector.WorkspaceExplorerTemplate>
<DataTemplate>
<v:WorkspaceExplorerView/>
</DataTemplate>
</pane:PanesTemplateSelector.WorkspaceExplorerTemplate>
<pane:PanesTemplateSelector.ToolBoxTemplate>
<DataTemplate>
<TextBlock>Test</TextBlock>
</DataTemplate>
</pane:PanesTemplateSelector.ToolBoxTemplate>
</pane:PanesTemplateSelector>
</avalonDock:DockingManager.LayoutItemTemplateSelector>
<avalonDock:DockingManager.LayoutUpdateStrategy>
<pane:LayoutInitializer/>
</avalonDock:DockingManager.LayoutUpdateStrategy>
<avalonDock:LayoutRoot>
<avalonDock:LayoutPanel Orientation="Horizontal">
<avalonDock:LayoutAnchorablePane Name="DockLeft" DockMinWidth="250"/>
<avalonDock:LayoutAnchorablePaneGroup>
<avalonDock:LayoutAnchorablePane Name="DockCenterTop" DockMinWidth="250"/>
<avalonDock:LayoutAnchorablePane Name="DockCenterBottom" DockMinWidth="250"/>
</avalonDock:LayoutAnchorablePaneGroup>
<avalonDock:LayoutAnchorablePane Name="DockRight" DockMinWidth="500"/>
</avalonDock:LayoutPanel>
</avalonDock:LayoutRoot>
我想在LayoutInitializer中指定以下内容:
使用模板“WorkspaceExplorerTemplate”的LayoutItems应该放在“DockLeft”里面,而带有模板“ToolBoxTemplate”的LayoutItems应该放在“DockRight”里面。
这可能吗?
我该怎么做?
我不希望得到详细的解释,但链接到一个很好的文档会很好。
提前致谢
到目前为止,LayoutInitializer看起来像这样:
class LayoutInitializer : ILayoutUpdateStrategy
{
public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
{
LayoutAnchorablePane destPane = destinationContainer as LayoutAnchorablePane;
if (destinationContainer != null &&
destinationContainer.FindParent<LayoutFloatingWindow>() != null)
return false;
var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "ToolsPane");
if (toolsPane != null)
{
toolsPane.Children.Add(anchorableToShow);
return true;
}
return false;
}
public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown)
{
}
public bool BeforeInsertDocument(LayoutRoot layout, LayoutDocument anchorableToShow, ILayoutContainer destinationContainer)
{
return false;
}
public void AfterInsertDocument(LayoutRoot layout, LayoutDocument anchorableShown)
{
}
答案 0 :(得分:1)
找到答案:
BeforeInsertAnchorable需要看一下这个:
public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
{
LayoutAnchorablePane destPane = destinationContainer as LayoutAnchorablePane;
if (destinationContainer != null &&
destinationContainer.FindParent<LayoutFloatingWindow>() != null)
return false;
var DockLeftPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "DockLeft");
if (DockLeftPane != null)
{
if(anchorableToShow.Content.GetType() == typeof(WorkspaceExplorerViewModel))
DockLeftPane.Children.Add(anchorableToShow);
return true;
}
return false;
}