TabbedMdiHost + MVVM + LayoutSerialization

Docking/MDI for WPF Forum

Posted 6 months ago by Tommaso Giachi - CTO, Isendu srl
Version: 23.1.4
Avatar

Hi, I have this docking.
Where I have both the tools and the documents. When I go to deserialize it only restores the tools. If I switch to mdi, the layout is restored correctly.
Why ?

<docking:DockSite x:Name="DockSite"
                              DockPanel.Dock="Top" MdiKind="Tabbed"
                              DocumentItemTemplate="{StaticResource DockingWindowContentDataTemplate}"
                              DocumentItemContainerStyle="{StaticResource DocumentWindowStyle}"
                              ToolItemContainerStyle="{StaticResource ToolWindowStyle}"
                              ToolItemTemplate="{StaticResource DockingWindowContentDataTemplate}"
                              DocumentItemsSource="{Binding Workspace.Documents, UpdateSourceTrigger=PropertyChanged}"
                              ToolItemsSource="{Binding Workspace.Tools, UpdateSourceTrigger=PropertyChanged}">
                <docking:SplitContainer Orientation="Vertical">
                    <docking:Workspace>
                        <docking:TabbedMdiHost  />
                    </docking:Workspace>
                    <docking:ToolWindowContainer />
                </docking:SplitContainer>
            </docking:DockSite>
 if (args.Node != null)
        {
            var serializedToolId = layoutModel.Tools.Keys.FirstOrDefault(s => s == args.Node.SerializationId);

            if (serializedToolId != null)
            {
                var serializedToolType = layoutModel.Tools[serializedToolId];

                Logger.LogInformation(
                    "Restoring layout for {ToolId} - {Type}",
                    serializedToolId,
                    serializedToolType.ToolType
                );

                var stateSource = layoutModel.States.FirstOrDefault(x => x.ToolId == serializedToolId);

                object? state = null;

                if (stateSource != null)
                {
                    state = stateSource.State.FromJson(Type.GetType(stateSource.StateType));
                }

                var (toolViewModel, toolView) = await _workspaceService.BuildTool(
                    Type.GetType(serializedToolType.ToolType),
                    serializedToolId,
                    state
                );


                if (serializedToolType.ToolTypeEnum == ToolTypeEnum.Document)
                {
                    _workspaceService.Add(toolViewModel);

                    //  args.Window = dockSite.ContainerFromDocumentItem(toolViewModel);
                    args.Window = dockSite.ContainerFromDocumentItem(toolViewModel);

                    args.Window.ContainerDockedSize = args.Node.ContainerDockedSize;

                    if (args.Node.StandardMdiBounds != null)
                    {
                        args.Window.StandardMdiBounds = args.Node.StandardMdiBounds.Value;
                    }

                    args.Window.ContainerDockedSize = args.Node.ContainerDockedSize;
                }
                else
                {
                    _workspaceService.Add(toolViewModel);
                    args.Window = dockSite.ContainerFromToolItem(toolViewModel);
                }


                args.Handled = true;
                // await toolViewModel.OnShownAsync();
            }

Comments (1)

Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Layout serialization only works on tool windows by default.  You need to switch an option on the serializer to have it work on the entire layout (including MDI) if you want to also support document windows.  Here's the related documentation topic section for that option.  Are you setting that serializer option appropriately for your scenario?

Also can you clarify what you meant by "If I switch to mdi, the layout is restored correctly."?  It looks like you have MDI already in that code above.

It's difficult to know what is causing the problem without a full simple sample project to debug with.  If the option above doesn't solve the isuse, can you put together a new simple sample project that shows it happening?  Email a .zip containing the project and the steps to reproduce it to our support address.  Be sure to exclude the bin/obj folders from the .zip you send so it doesn't get spam blocked.  Then we can debug with that and sort out what's happening.  Thanks!


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.