Restore Layout

Jan 24, 2011 at 2:09 PM

Hi I am trying to use restore layout with DockableContent that I created in c# but I cant get it to work here is my code:

ExplorerWindow.cs

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using AvalonDock;

namespace MyFirstWPFApp
{
    class ExplorerWindow : DockableContent
    {
        public ExplorerWindow()
        {
            Title = "Explorer";
        }
    }
}

 

 

MainWindow.cs

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using AvalonDock;

namespace MyFirstWPFApp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    
    public partial class MainWindow : Window 
    {
        DockableContent explorerWindow = new DockableContent();
        DocumentPane   documentPane   = new DocumentPane();

        public MainWindow()
        {
            InitializeComponent();
            BuildDockLayout();
        }

        private void BuildDockLayout()
        {
            dockManager.Content = null;
            dockManager.Content = documentPane;
            explorerWindow.Show(dockManager, AnchorStyle.Left);
        }

        private void SaveLayout_Click(object sender, RoutedEventArgs e)
        {
            dockManager.SaveLayout("layout.xml");
        }

        private void LoadLayout_Click(object sender, RoutedEventArgs e)
        {
            dockManager.RestoreLayout("layout.xml");
        }
    }
}

 

 

When I try to restore the layout if explorerWindow is docked it then disappears, if it is floating then nothing happens.

Any suggestions welcome,

Thanks,
Eamonn 

Jan 26, 2011 at 9:45 AM

I found the solution by running with the source project in debug mode and found that becasue I wasnt setting the Name property for each Dockable Content the SaveLayout function was not working, maybe an error should be returned from this function so the user knows the function call failed?