无法在LayoutDocumentPane中的选项卡之间切换
本文关键字:之间 选项 LayoutDocumentPane | 更新日期: 2023-09-27 18:24:17
我在名为MainWindowPane的xaml中有LayoutDocumentPane。我正在使用以下代码以编程方式在窗格中添加选项卡。
MyViewer viewer = new MyViewer();
LayoutDocument tempTabItem = new LayoutDocument();
tempTabItem.Closed += onTabItemClosed;
tempTabItem.Content = viewer;
MainWindowPane.Children.Add(tempTabItem);
MainDockManager.ActiveContent = 0;
现在,选项卡已成功添加到窗口中,但当我单击任何其他选项卡时,我的应用程序都会崩溃,当我看到堆栈跟踪时,它会说它在onModelChanged()Function上崩溃。
请帮我解决这个问题。
经过大量调试,我的问题找到了解决方案。。
有一个线程问题,因为我的选项卡内的布局是使用后台工作程序初始化的,所以在我切换时并没有完全完成。
所以现在等待后台工作程序完成,然后添加新的选项卡。
试着把它作为代码不起作用的指南。我认为您可能正在使用LayoutDocumentPane
系列而不是LayoutAnchorablePane
。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<xcad:DockingManager>
<xcad:LayoutRoot>
<xcad:LayoutPanel Orientation="Horizontal">
<xcad:LayoutAnchorablePaneGroup DockWidth="125">
<xcad:LayoutAnchorablePane>
<xcad:LayoutAnchorable ContentId="alarms" Title="Alarms">
<ListBox Margin="-1,0,1,0">
<s:String>Alarm 1</s:String>
<s:String>Alarm 2</s:String>
<s:String>Alarm 3</s:String>
</ListBox>
</xcad:LayoutAnchorable>
<xcad:LayoutAnchorable ContentId="journal" Title="Journal" >
<RichTextBox>
<FlowDocument>
<Paragraph FontSize="14" FontFamily="Segoe">
This is the content of the Journal Pane.
<LineBreak/>
A
<Bold>RichTextBox</Bold> has been added here
</Paragraph>
</FlowDocument>
</RichTextBox>
</xcad:LayoutAnchorable>
</xcad:LayoutAnchorablePane>
</xcad:LayoutAnchorablePaneGroup>
</xcad:LayoutPanel>
</xcad:LayoutRoot>
</xcad:DockingManager>