serialization fails ?!

May 26, 2012 at 8:30 PM
Edited May 26, 2012 at 8:35 PM

hi

I'm trying to do some stuff with AvalonDock (version 2_0_0795) (i'm trying to write visual debugger for android since gdb console sucks for larger scale debugging) but i'v meet some errors:

here is layout of my MAIN window (WPF) [sorry for formatting :/]

 

 

<avalonDock:DockingManager Grid.Row="1" x:Name="DockManager" >
            <avalonDock:DockingManager.Theme>
                <avalonDock:VS2010Theme/>
            </avalonDock:DockingManager.Theme>

            <avalonDock:LayoutRoot x:Name="RootDocker">

                <avalonDock:LayoutPanel Orientation="Horizontal">
                    <avalonDock:LayoutDocumentPaneGroup>
                        <avalonDock:LayoutDocumentPane x:Name="DocumentsHostPane">
                        </avalonDock:LayoutDocumentPane>
                    </avalonDock:LayoutDocumentPaneGroup>
                </avalonDock:LayoutPanel>

                <avalonDock:LayoutRoot.LeftSide>
                    <avalonDock:LayoutAnchorSide x:Name="ProjectLayoutRoot">
                        <avalonDock:LayoutAnchorGroup x:Name="ProjectLayout" >

                            <avalonDock:LayoutAnchorable Title="Project" x:Name="ProjectHostPane">
                                <AndroidDebugBridge:ProjectTreeWindow x:Name="ProjectWindow"/>
                            </avalonDock:LayoutAnchorable>
                            
                        </avalonDock:LayoutAnchorGroup>
                    </avalonDock:LayoutAnchorSide>
                </avalonDock:LayoutRoot.LeftSide>
                <avalonDock:LayoutRoot.BottomSide>
                    <avalonDock:LayoutAnchorSide x:Name="LogsLayoutRoot">
                        <avalonDock:LayoutAnchorGroup x:Name="LogsLayout">
                            
                            <avalonDock:LayoutAnchorable Title="LogCat" x:Name="LogCatHostPane" AutoHideMinWidth="0" AutoHideHeight="100" AutoHideMinHeight="100" FloatingHeight="240" FloatingTop="240">
                                <AndroidDebugBridge:ADBLogWindow x:Name="LogCatWindow"/>
                            </avalonDock:LayoutAnchorable>

                            <avalonDock:LayoutAnchorable Title="Logs" x:Name="LogsHostPane" FloatingHeight="240" FloatingTop="240" AutoHideMinWidth="0" AutoHideHeight="100" AutoHideMinHeight="100">
                                <AndroidDebugBridge:OutLogWindow x:Name="LogWindow"/>
                            </avalonDock:LayoutAnchorable>
                            
                        </avalonDock:LayoutAnchorGroup>
                    </avalonDock:LayoutAnchorSide>
                </avalonDock:LayoutRoot.BottomSide>
            </avalonDock:LayoutRoot>
        </avalonDock:DockingManager>

 

 

and all is fine - i have what i want (OutLogWindow, ADBLogWindow and ProjectTreeWindow are all UserControl object with bunch of WPF controlls inside (and some of those controlls contains WindowsFormsHost with in turn host ScintillaNET and other custom controlls)

but at the app exit I want to remember the position of all windows

 

        private void SaveLayout()
        {
            try
            {
                var Serializer = new XmlLayoutSerializer(DockManager);
                using (var Stream = new StreamWriter(@".\ADBLayout.config"))
                    Serializer.Serialize(Stream);
            }

            catch(Exception ex)
            {
                AddToLog(Brushes.DarkRed, ex.Message);
            }

            return;
        }
it puts some rablings to debugOut - but do not throw any exceptions, the file also looks fine but then after program start I want to restore the layout
        private void LoadLayout()
        {
            try
            {
                if (!File.Exists(@".\ADBLayout.config"))
                    return;

                var Serializer = new XmlLayoutSerializer(DockManager);
                using (var Stream = new StreamReader(@".\ADBLayout.config"))
                    Serializer.Deserialize(Stream);
            }

            catch(Exception ex)
            {
                AddToLog(Brushes.DarkRed, ex.Message);
            }

            return;
        }
but instead of restoring layout i'm getting empty main window ... whats going on (i call LoadLayout() as the last function of MainForm ctor ... (but i'v tried to call it from menu - it is all that same -- all windows all gone) is there something wrong with my layout or it is a bug ? [basically, left pane for project tree, two bottom panes for log, and adb out, center pane for document tabs (added from code - but at the serialization time no documents were open)]

thanks for any info on this
May 28, 2012 at 1:58 PM
Edited May 28, 2012 at 1:59 PM

I don't know if you already found the solution here, anyway you need to set the contentId for all contents (instead of the x:Name) and handle the serialization callback:

               serializer.LayoutSerializationCallback += (s, args) =>
                {
                    if (args.Model.ContentId == "winFormsHost")
                        args.Content = winFormsHost;
                };

Jun 3, 2012 at 9:25 AM

ok i'v managed to get this to work -- but only PARTIALY ...

look at 'DocumentsHostPane' - it have no content in XAML, its (ContentID == null) while deserializing

but later I'm addig new documents to it - and it works IF I do not 'deserialize' prior to add, if I add after deserialization that it crashes in:

LayoutContent.cs : 553 (Root.Manager.StartDraggingFloatingWindowForContent(this, false);) -- Manager is null

any ideas why ?

 

currently my layout is:

 

        <avalonDock:DockingManager Grid.Row="1" x:Name="DockManager" >
            <avalonDock:DockingManager.Theme>
                <avalonDock:VS2010Theme/>
            </avalonDock:DockingManager.Theme>
            <avalonDock:LayoutRoot x:Name="RootDocker">

                <avalonDock:LayoutPanel x:Name="MainPane" Orientation="Vertical">

                    <avalonDock:LayoutDocumentPaneGroup DockMinHeight="320" DockMinWidth="320">
                        <avalonDock:LayoutDocumentPane x:Name="DocumentsHostPane" DockMinHeight="320" DockMinWidth="320">
                        </avalonDock:LayoutDocumentPane>
                    </avalonDock:LayoutDocumentPaneGroup>

                    <avalonDock:LayoutAnchorablePaneGroup DockHeight="290" DockMinHeight="290" FloatingHeight="290" Orientation="Vertical" DockMinWidth="320" FloatingWidth="320">
                        <avalonDock:LayoutAnchorablePane DockMinHeight="290" DockMinWidth="320">

                            <avalonDock:LayoutAnchorable Title="Logs" x:Name="LogsHostPane" AutoHideHeight="290" AutoHideMinHeight="290" AutoHideMinWidth="320" AutoHideWidth="320" FloatingHeight="290">
                                <AndroidDebugBridge:OutLogWindow x:Name="LogWindow" MinWidth="320" />
                            </avalonDock:LayoutAnchorable>

                            <avalonDock:LayoutAnchorable Title="LogCat" x:Name="LogCatHostPane" AutoHideHeight="290" AutoHideMinHeight="290" FloatingHeight="290" AutoHideMinWidth="320" AutoHideWidth="320">
                                <AndroidDebugBridge:ADBLogWindow x:Name="LogCatWindow" MinWidth="320" />
                            </avalonDock:LayoutAnchorable>

                            <avalonDock:LayoutAnchorable Title="Breakpoints" x:Name="BreakpointsHostPane" AutoHideHeight="290" AutoHideMinHeight="290" FloatingHeight="290" AutoHideMinWidth="320" AutoHideWidth="320">
                                <AndroidDebugBridge:BreakpointsManager x:Name="BreakpointsWindow" MinWidth="320" />
                            </avalonDock:LayoutAnchorable>

                        </avalonDock:LayoutAnchorablePane>
                    </avalonDock:LayoutAnchorablePaneGroup>

                </avalonDock:LayoutPanel>

                <avalonDock:LayoutRoot.LeftSide>
                    <avalonDock:LayoutAnchorSide x:Name="ProjectLayoutRoot">
                        <avalonDock:LayoutAnchorGroup x:Name="ProjectLayout" >

                            <avalonDock:LayoutAnchorable Title="Project" x:Name="ProjectHostPane" AutoHideMinWidth="240" AutoHideWidth="240" FloatingWidth="240">
                                <AndroidDebugBridge:ProjectTreeWindow x:Name="ProjectWindow"/>
                            </avalonDock:LayoutAnchorable>

                        </avalonDock:LayoutAnchorGroup>
                    </avalonDock:LayoutAnchorSide>
                </avalonDock:LayoutRoot.LeftSide>

            </avalonDock:LayoutRoot>
        </avalonDock:DockingManager>

my C# code is

 

      private void SaveLayout()
        {
            try
            {
                var Serializer = new XmlLayoutSerializer(DockManager);
                using (var Stream = new StreamWriter(@".\ADBLayout.config"))
                    Serializer.Serialize(Stream);
            }

            catch(Exception ex)
            {
                AddToLog(Brushes.DarkRed, ex.Message);
            }

            return;
        }

        private void LoadLayout()
        {
            try
            {
                if (!File.Exists(@".\ADBLayout.config"))
                    return;

                var Serializer = new XmlLayoutSerializer(DockManager);

                Serializer.LayoutSerializationCallback += (s, args) =>
                {
                    if (args.Model.ContentId == "LogWindow")
                        args.Content = LogWindow;

                    if (args.Model.ContentId == "LogCatWindow")
                        args.Content = LogCatWindow;

                    if (args.Model.ContentId == "BreakpointsWindow")
                        args.Content = BreakpointsWindow;

                    if (args.Model.ContentId == "ProjectWindow")
                        args.Content = ProjectWindow;
                };

                using (var Stream = new StreamReader(@".\ADBLayout.config"))
                    Serializer.Deserialize(Stream);
            }

            catch(Exception ex)
            {
                AddToLog(Brushes.DarkRed, ex.Message);
            }

            return;
        }