Simple repro follows. Using the "Add new tab" button will stop working after clicking the "Deserialize" button. Even if re-serializing and deserializing, the new tabs are not visible.
Repro XAML:
```
<Window x:Class="AvalonDockTabsTest2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AvalonDockTabsTest2"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"
Orientation="Horizontal">
<Button Content="Add new tab"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="4"
Click="OnAddTabClick" />
<Button Content="Serialize"
Margin="4"
Click="OnSerialize" />
<Button Content="Deserialize"
Margin="4"
Click="OnDeserialize" />
</StackPanel>
<xcad:DockingManager Grid.Row="1" x:Name="DockingManager">
<xcad:LayoutRoot>
<xcad:LayoutPanel>
<xcad:LayoutDocumentPaneGroup>
<xcad:LayoutDocumentPane x:Name="DocPane">
<xcad:LayoutDocument Title="Default" CanClose="False" />
</xcad:LayoutDocumentPane>
</xcad:LayoutDocumentPaneGroup>
</xcad:LayoutPanel>
</xcad:LayoutRoot>
</xcad:DockingManager>
</Grid>
</Window>
```
Repro code-behind:
```
namespace AvalonDockTabsTest2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
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 = "test " + this.count;
doc.ContentId = "test" + 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());
}
}
}
}
```
Comments: ** Comment from web user: BoucherS **
Hi,
First, your Default LayoutDocument is missing its ContentId. This means it will not be serialized/deserialized.
Second, in your OnTabClick handler, you do :
```
this.DocPane.Children.Add( doc );
```
but this will only add items into the "DocPane", which will be a different instance upon deserialization. You should try to obtain this LayoutDocumentPane by scanning the DockingManager and adding the new item in it. Something like :
```
var layoutDocumentPaneGroup = ((LayoutDocumentPaneGroupControl)DockingManager.LayoutRootPanel.Children[ 0 ]).Model;
var layoutDocumentPane = layoutDocumentPaneGroup.Descendents().OfType<LayoutDocumentPane>().First();
layoutDocumentPane.Children.Add( doc );
```
Third, Please note v3.2 and v3.3 will not deserialize when using a StringReader. In those version, you will need to use a StreamReader. This will all be fixed in v3.4.
Here's an example of using StreamReader:
```
private void OnSerialize( object sender, RoutedEventArgs e )
{
var layoutSerializer = new XmlLayoutSerializer( DockingManager );
using( var writer = new StreamWriter( "AvalonDockSavedFile.txt" ) )
{
layoutSerializer.Serialize( writer );
}
}
private void OnDeserialize( object sender, RoutedEventArgs e )
{
var layoutSerializer = new XmlLayoutSerializer( DockingManager );
using( var reader = new StreamReader( "AvalonDockSavedFile.txt" ) )
{
layoutSerializer.Deserialize( reader );
}
}
```
――――
_Get more controls, features, updates and technical support with [Xceed Toolkit Plus for WPF](https://wpftoolkit.codeplex.com/wikipage?title=Compare%20Editions)_