gpt4 book ai didi

wpf - BeforeInsertAnchorable从不调用(Avalon Dock 3.2.0.0)

转载 作者:行者123 更新时间:2023-12-03 10:32:43 25 4
gpt4 key购买 nike

我试图将 anchor 添加到特定的目标。为了做到这一点,我尝试实现ILayoutUpdateStrategy:

public class DockingContentInitializer : ILayoutUpdateStrategy
{
public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown)
{

}

public void AfterInsertDocument(LayoutRoot layout, LayoutDocument anchorableShown)
{

}

public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
{
LayoutAnchorablePane _Destination = destinationContainer as LayoutAnchorablePane;
if (destinationContainer != null &&destinationContainer.FindParent<LayoutFloatingWindow>() != null)
return false;
if(anchorableToShow.Content is IMainAnchorContent)
{
if(layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "MainPane") == null)
{
LayoutAnchorablePane MainPane = new LayoutAnchorablePane();
MainPane.Name = "MainPane";
layout.RootPanel.Children.Insert(0, MainPane);
MainPane.Children.Add(anchorableToShow);
return true;
}
else
{
(layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "MainPane") as LayoutAnchorablePane).Children.Add(anchorableToShow);
return true;
}

}
if (anchorableToShow.Content is IAdditionalAnchorContent)
{
if (layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "AdditionPane") == null)
{
LayoutAnchorablePane Pane = new LayoutAnchorablePane();
Pane.Name = "AdditionPane";
layout.RootPanel.Children.Add(Pane);
Pane.Children.Add(anchorableToShow);
return true;
}
else
{
(layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "AdditionPane") as LayoutAnchorablePane).Children.Add(anchorableToShow);
return true;
}

}
return false;
}

public bool BeforeInsertDocument(LayoutRoot layout, LayoutDocument anchorableToShow, ILayoutContainer destinationContainer)
{
return false;
}

MainView.xaml
 <avalon:DockingManager x:Name="DockManager" 
Grid.Row="2"
BorderBrush="Black"
Margin="3"
Background="#FFFDFDFD"
BorderThickness="0"
DataContext="{Binding DockingManager}"
DocumentsSource="{Binding Documents}"
AnchorablesSource="{Binding Anchorables}">

<avalon:DockingManager.Resources>
<DataTemplate DataType="{x:Type vm:ProjectTreeViewModel}">
<local:ProjectTreeView />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:ComponentTreeViewModel}">
<local:ComponentTreeView />
</DataTemplate>
</avalon:DockingManager.Resources>`<avalon:DockingManager.LayoutUpdateStrategy>
<behaviors:DockingContentInitializer />
</avalon:DockingManager.LayoutUpdateStrategy>
<avalon:DockingManager.LayoutItemContainerStyle>
<Style TargetType="{x:Type avalonctrl:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Title}"/>
<Setter Property="CloseCommand" Value="{Binding Model.CloseTabCommand}"/>
<Setter Property="CanClose" Value="{Binding Model.CanCloseTab}"/>
</Style>
</avalon:DockingManager.LayoutItemContainerStyle>
</avalon:DockingManager>`

我的 View 模型添加正确,但是从不调用BeforeInsertAnchorable方法,这导致将 View 模型放置在右侧的默认AnchorablePane中。
我哪里错了?

最佳答案

好吧,我弄清楚了-我使用MVVM Light在将 View 加载到DockingManager之前初始化了带有 anchor 定集合的viewModel。多数民众赞成在RootPanel中创建两个布局而不是一个,看起来像是引起了问题。

现在,我在DockingManager被“加载”之前等待,然后才将元素放入我的Anchorable集合中。

关于wpf - BeforeInsertAnchorable从不调用(Avalon Dock 3.2.0.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49967563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com