Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式将LayoutAnchorable添加到DockManager_C#_Wpf_Avalondock - Fatal编程技术网

C# 以编程方式将LayoutAnchorable添加到DockManager

C# 以编程方式将LayoutAnchorable添加到DockManager,c#,wpf,avalondock,C#,Wpf,Avalondock,我正试图以编程方式向我的AvalonDockDockingManager实例添加一个新的LayoutOnTable 使用下面的代码,锚定出现,但为空(内容不显示),按钮不工作(浮动、自动隐藏、关闭等) 在将控件(在运行时)拖入和拖出myLayoutDocumentPane之后,该控件确实开始按预期工作,尽管关闭按钮没有出现(这是一个单独的问题) 我试过导航AvalonDock源代码,但是没有明显的东西可以找到 我希望以编程方式添加,而不是使用MVVM。如果您希望始终添加到要从中添加的文档的同一窗

我正试图以编程方式向我的AvalonDock
DockingManager
实例添加一个新的
LayoutOnTable

使用下面的代码,锚定出现,但为空(内容不显示),按钮不工作(浮动、自动隐藏、关闭等)

在将控件(在运行时)拖入和拖出my
LayoutDocumentPane
之后,该控件确实开始按预期工作,尽管关闭按钮没有出现(这是一个单独的问题)

我试过导航AvalonDock源代码,但是没有明显的东西可以找到


我希望以编程方式添加,而不是使用MVVM。

如果您希望始终添加到要从中添加的文档的同一窗格中,您可以这样做。
HomePage.HomePage
是包含停靠管理器的窗口的静态成员。
doc
是对当前文档的引用

LayoutDocument ld = new LayoutDocument();
ld.Content = new NewDonor(ld);
LayoutDocumentPane pane =  ((doc.FindParent<LayoutDocumentPane>() ?? (HomePage.homepage.panal.Children?[0] as LayoutDocumentPane)) ?? new LayoutDocumentPane());
pane.Children.Add(ld);
if (HomePage.homepage.panal.ChildrenCount == 0)
{
    HomePage.homepage.panal.Children.Add(pane);
}
ld.IsSelected = true;
LayoutDocument ld=new LayoutDocument();
ld.Content=新的新捐赠者(ld);
LayoutDocumentPane=((doc.FindParent()??(HomePage.HomePage.panal.Children?[0]作为LayoutDocumentPane))???新建LayoutDocumentPane());
窗格.Children.Add(ld);
如果(HomePage.HomePage.panal.ChildrenCount==0)
{
HomePage.HomePage.panal.Children.Add(窗格);
}
ld.IsSelected=true;

您使用的是什么版本的avalondock?1.3或2.0?我使用的是2.0版。我遇到了一个问题,如果我的docking manager在xaml上没有面板,它就根本不会显示面板(也会在运行时添加)。我最终做的是在xaml中添加占位符,并在应用程序启动时删除它们,这似乎确实奏效了。不幸的是,我已经指定了一个
LayoutPanel
。我遇到了同样的问题。你找到答案了吗?
LayoutDocument ld = new LayoutDocument();
ld.Content = new NewDonor(ld);
LayoutDocumentPane pane =  ((doc.FindParent<LayoutDocumentPane>() ?? (HomePage.homepage.panal.Children?[0] as LayoutDocumentPane)) ?? new LayoutDocumentPane());
pane.Children.Add(ld);
if (HomePage.homepage.panal.ChildrenCount == 0)
{
    HomePage.homepage.panal.Children.Add(pane);
}
ld.IsSelected = true;