State Persistence in WPF Tabbed MDI Form (DocumentContainer)

This topic illustrates loading and saving the dock state in various places. It also gives information about resetting and deleting the states.

Load and Save in Registry

In the Document Container, you can save and load dock states into the Registry using the SaveDockState and LoadDockState methods. Refer to the following code snippet for setting these methods.

  • c#
  • // Code to Save State:
    
    BinaryFormatter formatter1 = new BinaryFormatter();
    
    DocContainer.SaveDockState(formatter1);
    
    
    
    // Code to Load State:
    
    BinaryFormatter formatter1 = new BinaryFormatter();
    
    DocContainer.LoadDockState(formatter1);

    Load and Save in Isolated Storage

    In the Document Container you can Load/Save/Reset the dock state in the Isolated Storage. To Load, Save and Reset, use the following code snippet.

  • c#
  • // Code to Save:
    
    DocContainer.SaveDockState();
    
    
    
    // Code to Load:
    
    DocContainer.LoadDockState();
    
    
    
    // Code to Reset:
    
    DocContainer.DeleteInternalIsolatedStorage();

    Load and Save in XML

    You can save and load the data for the Document Container in XML also. To Load and Save data in XML use the following code snippet. This is done by using both Binary Formatter as well as Soap Formatter as follows.

  • c#
  • // Code to Save in XML using Binary Formatter:
    
    BinaryFormatter formatter1 = new BinaryFormatter();
    
    DocContainer.SaveDockState(formatter1, StorageFormat.Xml, @"d:\docum_xml.xml");
    
    
    
    // Code save in XML using SOAP formatter:
    
    SoapFormatter formatter1 = new SoapFormatter();
    
    DocContainer.SaveDockState(formatter1, StorageFormat.Xml, @"d:\docum_xml.xml");
    
    
    
    // Code to Load XML using Binary formatter:
    
    BinaryFormatter formatter1 = new BinaryFormatter();
    
    DocContainer.LoadDockState(formatter1, StorageFormat.Xml, @"d:\docum_xml.xml");
    
    
    
    // Code to Load XML using Soap Formatter:
    
    SoapFormatter formatter1 = new SoapFormatter();
    
    DocContainer.LoadDockState(formatter1, StorageFormat.Xml, @"d:\docum_xml.xml");

    Load and Save in Bin

    Document Container enables the user to save and load the data in BIN. Refer to the following code snippet for saving or loading data in BIN. This is achieved by using Binary Formatter and Soap Formatter as well.

  • c#
  • // Code to Save Using Binary Formatter:
    
    BinaryFormatter formatter1 = new BinaryFormatter();
    
    DocContainer.SaveDockState(formatter1, StorageFormat.Binary, @"d:\docum_bin.bin");
    
    
    
    // Code to Save Using Soap Formatter:
    
    SoapFormatter formatter1 = new SoapFormatter();
    
    DocContainer.SaveDockState(formatter1, StorageFormat.Binary, @"d:\docum_bin.bin");
    
    
    
    // Code to Load using Binary Formatter:
    
    BinaryFormatter formatter1 = new BinaryFormatter();
    
    DocContainer.LoadDockState(formatter1, StorageFormat.Binary, @"d:\docum_bin.bin");
    
    
    
    // Code to Load using Soap Formatter:
    
    SoapFormatter formatter1 = new SoapFormatter();
    
    DocContainer.LoadDockState(formatter1, StorageFormat.Binary, @"d:\docum_bin.bin");

    Reset the states in Document Container

    You can easily reset the states in Document Container by using the ResetState method as in the below code snippet.

  • c#
  • DocumentContainer DocContainer = new DocumentContainer();
    
    
    
    // Reset the states
    
    DocContainer.ResetState();

    Delete the State

    You can delete all the states you have created in the Document Container by using the DeleteDockState property. Refer to the below code example.

  • c#
  • DocContainer.DeleteDockState(@"d:\docum_xml.xml");
    
    DocContainer.DeleteDockState(@"d:\docum_bin.bin");
    
    DocContainer.DeleteDockState();