Back to Devexpress

WorkspaceManager.LoadWorkspace(String, Stream, Boolean) Method

windowsforms-devexpress-dot-utils-dot-workspacemanager-dot-loadworkspace-x28-system-dot-string-system-dot-io-dot-stream-system-dot-boolean-x29.md

latest6.1 KB
Original Source

WorkspaceManager.LoadWorkspace(String, Stream, Boolean) Method

SECURITY-RELATED CONSIDERATIONS

Deserializing layout settings from untrusted resources may create security issues. Review the following help topic for additional information: Safe Deserialization.

Loads a workspace from the target stream and places this workspace in the WorkspaceManager.Workspaces collection under the specific name.

Namespace : DevExpress.Utils

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
public bool LoadWorkspace(
    string name,
    Stream stream,
    bool getNameFromData
)
vb
Public Function LoadWorkspace(
    name As String,
    stream As Stream,
    getNameFromData As Boolean
) As Boolean

Parameters

NameTypeDescription
nameString

A String value that is the name this workspace will have in the WorkspaceManager.Workspaces collection.

| | stream | Stream |

A Stream that contains the desired workspace.

| | getNameFromData | Boolean |

true if the workspace name written in a stream has a priority over the name parameter of this method; otherwise, false.

|

Returns

TypeDescription
Boolean

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

|

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.

csharp
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);
 }
vb
Dim file As String = "layout.xml"
Dim workspaceName1 As String = "MyLayout"

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ' Use the WorkspaceManager to handle the layout of DevExpress controls that reside within the current form.
    WorkspaceManager1.TargetControl = Me

    ' 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) Then
        WorkspaceManager1.ApplyWorkspace(workspaceName1)
    End If
End Sub

Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
    ' Save DevExpress controls' layouts to a file
    WorkspaceManager1.CaptureWorkspace(workspaceName1, True)
    WorkspaceManager1.SaveWorkspace(workspaceName1, file, True)
End Sub

See Also

WorkspaceManager Class

WorkspaceManager Members

DevExpress.Utils Namespace