Permalink
Browse files

#78 - Fix ObjectDisposedException in sample

When loading from XML the explicitly referenced controls were not being
recreated (like the toolbox, etc; where there is a private member
holding a reference to the form).  Solution is to recreate these forms
before attempting to load from XML, just as load from code is doing.
  • Loading branch information...
1 parent 216e0de commit 569ee5e7c0df4f2cb5097940300a3e0dc54dce52 Ryan Rastedt committed Mar 11, 2013
Showing with 19 additions and 11 deletions.
  1. +19 −11 DockSample/MainForm.cs
View
30 DockSample/MainForm.cs
@@ -14,19 +14,20 @@ public partial class MainForm : Form
{
private bool m_bSaveLayout = true;
private DeserializeDockContent m_deserializeDockContent;
- private DummySolutionExplorer m_solutionExplorer = new DummySolutionExplorer();
- private DummyPropertyWindow m_propertyWindow = new DummyPropertyWindow();
- private DummyToolbox m_toolbox = new DummyToolbox();
- private DummyOutputWindow m_outputWindow = new DummyOutputWindow();
- private DummyTaskList m_taskList = new DummyTaskList();
+ private DummySolutionExplorer m_solutionExplorer;
+ private DummyPropertyWindow m_propertyWindow;
+ private DummyToolbox m_toolbox;
+ private DummyOutputWindow m_outputWindow;
+ private DummyTaskList m_taskList;
public MainForm()
{
InitializeComponent();
+ CreateStandardControls();
+
showRightToLeft.Checked = (RightToLeft == RightToLeft.Yes);
RightToLeftLayout = showRightToLeft.Checked;
- m_solutionExplorer = new DummySolutionExplorer();
m_solutionExplorer.RightToLeftLayout = RightToLeftLayout;
m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
}
@@ -423,11 +424,7 @@ private void menuItemLayoutByCode_Click(object sender, System.EventArgs e)
CloseAllDocuments();
- m_solutionExplorer = new DummySolutionExplorer();
- m_propertyWindow = new DummyPropertyWindow();
- m_toolbox = new DummyToolbox();
- m_outputWindow = new DummyOutputWindow();
- m_taskList = new DummyTaskList();
+ CreateStandardControls();
m_solutionExplorer.Show(dockPanel, DockState.DockRight);
m_propertyWindow.Show(m_solutionExplorer.Pane, m_solutionExplorer);
@@ -447,13 +444,24 @@ private void menuItemLayoutByCode_Click(object sender, System.EventArgs e)
dockPanel.ResumeLayout(true, true);
}
+ private void CreateStandardControls()
+ {
+ m_solutionExplorer = new DummySolutionExplorer();
+ m_propertyWindow = new DummyPropertyWindow();
+ m_toolbox = new DummyToolbox();
+ m_outputWindow = new DummyOutputWindow();
+ m_taskList = new DummyTaskList();
+ }
+
private void menuItemLayoutByXml_Click(object sender, System.EventArgs e)
{
dockPanel.SuspendLayout(true);
// In order to load layout from XML, we need to close all the DockContents
CloseAllContents();
+ CreateStandardControls();
+
Assembly assembly = Assembly.GetAssembly(typeof(MainForm));
Stream xmlStream = assembly.GetManifestResourceStream("DockSample.Resources.DockPanel.xml");
dockPanel.LoadFromXml(xmlStream, m_deserializeDockContent);

0 comments on commit 569ee5e

Please sign in to comment.