Xceed.Wpf.AvalonDock: 以编程方式创建选项卡式窗格
Xceed.Wpf.AvalonDock: Create tabbed panes programmatically
我正在尝试使用以下代码以编程方式在选项卡栏内创建两个窗格:
var middlePanel = new LayoutPanel
{
Orientation = Orientation.Vertical,
DockHeight = new GridLength(250)
};
rootPanel.Children.Add(middlePanel);
var paneGroup = new LayoutAnchorablePaneGroup
{
DockHeight = new GridLength(200)
};
middlePanel.Children.Add(new LayoutDocumentPane());
middlePanel.Children.Add(paneGroup);
var validationEditorPane = new LayoutAnchorablePane();
paneGroup.Children.Add(validationEditorPane);
validationEditorPane.Children.Add(new LayoutAnchorable { ContentId = "Validation", Title = "Validation" });
var searchEditorPane = new LayoutAnchorablePane();
paneGroup.Children.Add(searchEditorPane);
searchEditorPane.Children.Add(new LayoutAnchorable { ContentId = "Search", Title = "Search" });
但是,上面的代码创建了两个没有标签的相邻窗格。在运行时,我可以将搜索窗格拖到验证窗格上以将它们移动到选项卡中。这表明必须有可能以编程方式实现这一点,但我看不出如何实现。
有什么建议吗?
事实证明这比我想象的要容易。我所要做的就是将 LayoutAnchorable
添加到同一个 LayoutAnchorablePane
对象:
var tabPane = new LayoutAnchorablePane();
paneGroup.Children.Add(tabPane);
tabPane.Children.Add(new LayoutAnchorable { ContentId = "Validation", Title = "Validation" });
tabPane.Children.Add(new LayoutAnchorable { ContentId = "Search", Title = "Search" });
我正在尝试使用以下代码以编程方式在选项卡栏内创建两个窗格:
var middlePanel = new LayoutPanel
{
Orientation = Orientation.Vertical,
DockHeight = new GridLength(250)
};
rootPanel.Children.Add(middlePanel);
var paneGroup = new LayoutAnchorablePaneGroup
{
DockHeight = new GridLength(200)
};
middlePanel.Children.Add(new LayoutDocumentPane());
middlePanel.Children.Add(paneGroup);
var validationEditorPane = new LayoutAnchorablePane();
paneGroup.Children.Add(validationEditorPane);
validationEditorPane.Children.Add(new LayoutAnchorable { ContentId = "Validation", Title = "Validation" });
var searchEditorPane = new LayoutAnchorablePane();
paneGroup.Children.Add(searchEditorPane);
searchEditorPane.Children.Add(new LayoutAnchorable { ContentId = "Search", Title = "Search" });
但是,上面的代码创建了两个没有标签的相邻窗格。在运行时,我可以将搜索窗格拖到验证窗格上以将它们移动到选项卡中。这表明必须有可能以编程方式实现这一点,但我看不出如何实现。
有什么建议吗?
事实证明这比我想象的要容易。我所要做的就是将 LayoutAnchorable
添加到同一个 LayoutAnchorablePane
对象:
var tabPane = new LayoutAnchorablePane();
paneGroup.Children.Add(tabPane);
tabPane.Children.Add(new LayoutAnchorable { ContentId = "Validation", Title = "Validation" });
tabPane.Children.Add(new LayoutAnchorable { ContentId = "Search", Title = "Search" });