Description
theficus[CodePlex]
Being able to add new LayoutDocuments to a LayoutDocumentPane by using code behind (pane.Children.Add() stops working after you deserialize a layout.
Simple repro follows. Using the quotAdd new tabquot button will stop working after clicking the quotDeserializequot button. Even if re-serializing and deserializing, the new tabs are not visible.
Repro XAML:
ltWindow x:Class=quotAvalonDockTabsTest2.MainWindowquot
xmlns=quothttp://schemas.microsoft.com/winfx/2006/xaml/presentationquot
xmlns:x=quothttp://schemas.microsoft.com/winfx/2006/xamlquot
xmlns:d=quothttp://schemas.microsoft.com/expression/blend/2008quot
xmlns:mc=quothttp://schemas.openxmlformats.org/markup-compatibility/2006quot
xmlns:local=quotclr-namespace:AvalonDockTabsTest2quot
xmlns:xcad=quothttp://schemas.xceed.com/wpf/xaml/avalondockquot
mc:Ignorable=quotdquot
Title=quotMainWindowquot Height=quot350quot Width=quot525quotgt
ltGridgt
ltGrid.RowDefinitionsgt
ltRowDefinition Height=quot30quot /gt
ltRowDefinition Height=quot*quot /gt
lt/Grid.RowDefinitionsgt
ltStackPanel Grid.Row=quot0quot
Orientation=quotHorizontalquotgt
ltButton Content=quotAdd new tabquot
VerticalAlignment=quotCenterquot
HorizontalAlignment=quotLeftquot
Margin=quot4quot
Click=quotOnAddTabClickquot /gt
ltButton Content=quotSerializequot
Margin=quot4quot
Click=quotOnSerializequot /gt
ltButton Content=quotDeserializequot
Margin=quot4quot
Click=quotOnDeserializequot /gt
lt/StackPanelgt
ltxcad:DockingManager Grid.Row=quot1quot x:Name=quotDockingManagerquotgt
ltxcad:LayoutRootgt
ltxcad:LayoutPanelgt
ltxcad:LayoutDocumentPaneGroupgt
ltxcad:LayoutDocumentPane x:Name=quotDocPanequotgt
ltxcad:LayoutDocument Title=quotDefaultquot CanClose=quotFalsequot /gt
lt/xcad:LayoutDocumentPanegt
lt/xcad:LayoutDocumentPaneGroupgt
lt/xcad:LayoutPanelgt
lt/xcad:LayoutRootgt
lt/xcad:DockingManagergt
lt/Gridgt
lt/Windowgt
Repro code-behind:
namespace AvalonDockTabsTest2
{
/// ltsummarygt
/// Interaction logic for MainWindow.xaml
/// lt/summarygt
public partial class MainWindow : Window
{
private int count;
private string serializedLayout;
public MainWindow()
{
this.InitializeComponent();
}
private void OnAddTabClick(object sender, RoutedEventArgs e)
{
LayoutDocument doc = new LayoutDocument();
doc.Title = quottest quot + this.count;
doc.ContentId = quottestquot + this.count;
doc.Content = new Grid();
++this.count;
this.DocPane.Children.Add(doc);
}
private void OnDeserialize(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(this.serializedLayout))
{
this.OnSerialize(null, null);
}
XmlLayoutSerializer serializer = new XmlLayoutSerializer(this.DockingManager);
using (StringReader sr = new StringReader(this.serializedLayout))
{
XmlReader xr = XmlReader.Create(sr);
serializer.Deserialize(xr);
}
}
private void OnSerialize(object sender, RoutedEventArgs e)
{
XmlLayoutSerializer serializer = new XmlLayoutSerializer(this.DockingManager);
using (MemoryStream ms = new MemoryStream())
{
serializer.Serialize(ms);
this.serializedLayout = Encoding.ASCII.GetString(ms.ToArray());
}
}
}
}