Dirkster99 / AvalonDock

Our own development branch of the well known WPF document docking library
Microsoft Public License
1.39k stars 318 forks source link

Try set Content Control of LayoutContet In LayoutSerializationCallback, but no panel shows up #443

Closed KaivnD closed 1 year ago

KaivnD commented 1 year ago

Hi everyone! I'm trying to implement layout restore in my app, but I got some troubles. I found similar issue #397, but it's not helping with this.

here is xml content

<?xml version="1.0"?>
<LayoutRoot>
  <RootPanel Orientation="Horizontal">
    <LayoutPanel Orientation="Vertical">
      <LayoutDocumentPane>
      </LayoutDocumentPane>
    </LayoutPanel>
    <LayoutAnchorablePaneGroup Orientation="Vertical" DockWidth="250">
      <LayoutAnchorablePane DockWidth="250">
        <LayoutAnchorable Title="AssetExplorer" IsSelected="True"
          ContentId="ProjectAssetExplorerPanel" />
      </LayoutAnchorablePane>
      <LayoutAnchorablePane>
        <LayoutAnchorable Title="PropertyGrid" IsSelected="True" ContentId="PropertyGridPanel" />
        <LayoutAnchorable Title="ProjectSetting" ContentId="ProjectSettingPanel" />
      </LayoutAnchorablePane>
    </LayoutAnchorablePaneGroup>
  </RootPanel>
  <TopSide />
  <RightSide />
  <LeftSide />
  <BottomSide />
  <FloatingWindows />
  <Hidden />
</LayoutRoot>

this layout should be like this WcV7LfAJuf

here is serialization callback

serializer.LayoutSerializationCallback += (s, e) =>
{
    var item = e.Model;
    if (string.IsNullOrEmpty(item.ContentId)) return;    
    if (!RecreatePanelContent(item.ContentId, out FrameworkElement element)) return;
    item.Content = element; // this line will make everything disppear, but I what to restore panel content here.
};

here is xaml part

<avalon:DockingManager
    Name="DockRoot"
    AllowMixedOrientation="True"
    GridSplitterHeight="2"
    GridSplitterWidth="2" />
KaivnD commented 1 year ago

sorry, my bad. I forgot to show all panel after deserialize

  serializer.Deserialize(stream);

  foreach(var item in GetAllAnchorables())
  {
      item.Show();
  }