Skip to main content

WorkspaceManager.LoadWorkspace(String, Object) Method

Loads a workspace from the target local file and places it in the WorkspaceManager.Workspaces collection under the specific name.

Namespace: DevExpress.Utils

Assembly: DevExpress.Utils.v24.2.dll

Declaration

public bool LoadWorkspace(
    string name,
    object path
)

Parameters

Name Type Description
name String

A String value that is the name under which the loaded workspace is kept in the WorkspaceManager.Workspaces collection.

path Object

An Object that is the location of the file that stores a workspace.

Returns

Type Description
Boolean

true if the workspace was successfully loaded; otherwise, false.

Remarks

The LoadWorkspace method loads a workspace from a file and makes it available from the WorkspaceManager.Workspaces collection. However, this workspace remains inactive. To activate this workspace, use the WorkspaceManager.ApplyWorkspace method afterwards.

Example

The following code shows how to use the WorkspaceManager component to save the form’s bounds and state, and the layout of DevExpress controls when a form is closed, and load this layout when the form starts.

You may need to call the controls’ ForceInitialize methods (e.g., GridControl.ForceInitialize) before applying layouts to the controls in a Form.Load event handler.

 string file = "layout.xml";
 string workspaceName1 = "MyLayout";

 private void Form1_Load(object sender, EventArgs e) {
     //Use the WorkspaceManager to handle the layout of DevExpress controls that reside within the current form.
     workspaceManager1.TargetControl = this;

     // Save & restore the form's size, position and state along with DevExpress controls' layouts.
     workspaceManager1.SaveTargetControlSettings = true;

     // Disable layout load animation effects 
     workspaceManager1.AllowTransitionAnimation = DevExpress.Utils.DefaultBoolean.False;

    // Disable (de)serialization for the following controls (if required):
    //WorkspaceManager.SetSerializationEnabled(gaugeControl1, false);
    //WorkspaceManager.SetSerializationEnabled(accordionControl1, false);

    // When restoring layouts of controls in a Form.Load event handler,
    // you may need to call the controls' ForceInitialize methods to finish their initialization before restoring their layouts.
    //gridControl1.ForceInitialize();
    //dockManager1.ForceInitialize();
    //barManager1.ForceInitialize();
    //...

     //Load DevExpress controls' layouts from a file
     if (workspaceManager1.LoadWorkspace(workspaceName1, file, true))
         workspaceManager1.ApplyWorkspace(workspaceName1);
 }

 private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
     //Save DevExpress controls' layouts to a file
     workspaceManager1.CaptureWorkspace(workspaceName1, true);
     workspaceManager1.SaveWorkspace(workspaceName1, file, true);
 }

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the LoadWorkspace(String, Object) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also