需要 AvalonDock ILayoutUpdateStrategy 示例
AvalonDock ILayoutUpdateStrategy example needed
到目前为止,我主要使用 Edi and AvalonDockMVVM 来学习 AvalonDock 的工作原理,但都没有提供如何在我的应用程序中使用 ILayoutUpdateStrategy 的详细示例。
我的 Window 的 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".
里面
这可能吗?
我该怎么做?
我不希望得到详细的解释,但是 link 一个有据可查的示例会很棒。
提前致谢
到目前为止 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)
{
}
找到答案:
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;
}
到目前为止,我主要使用 Edi and AvalonDockMVVM 来学习 AvalonDock 的工作原理,但都没有提供如何在我的应用程序中使用 ILayoutUpdateStrategy 的详细示例。
我的 Window 的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".
里面这可能吗?
我该怎么做?
我不希望得到详细的解释,但是 link 一个有据可查的示例会很棒。
提前致谢
到目前为止 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)
{
}
找到答案:
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;
}