Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

LayoutSerializationService Class

Allows you to save/restore the layout of serializable DevExpress WPF Controls located on a View.

Namespace: DevExpress.Mvvm.UI

Assembly: DevExpress.Xpf.Core.v24.2.dll

NuGet Package: DevExpress.Wpf.Core

#Declaration

public class LayoutSerializationService :
    ServiceBase,
    ILayoutSerializationService

#Remarks

See LayoutSerializationService to learn more.

#Example

View Example

using System;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm;
using DevExpress.Mvvm.POCO;
using DocumentManagerSerialization.Properties;
using System.Collections.Generic;
using DocumentManagerSerialization.Common;

namespace DocumentManagerSerialization.ViewModels {
    [POCOViewModel]
    public class MainViewModel : ISupportLogicalLayout {

        public IDocumentManagerService DocumentManagerService { get { return this.GetService<IDocumentManagerService>(); } }
        public ILayoutSerializationService LayoutSerializationService { get { return this.GetService<ILayoutSerializationService>(); } }
        public virtual ViewModelState State { get; set; }

        public MainViewModel() {
            State = new ViewModelState() { State = "I'm Root!" };
        }

        [Command]
        public void OnWindowClosing() {
            Settings.Default.LogicalLayout = this.SerializeDocumentManagerService();
            Settings.Default.RootLayout = LayoutSerializationService.Serialize();
            Settings.Default.Save();
        }

        [Command]
        public void OnWindowLoaded() {
            if (Settings.Default.LogicalLayout != null) {
                this.RestoreDocumentManagerService(Settings.Default.LogicalLayout);
            }
            if (Settings.Default.RootLayout != null) {
                LayoutSerializationService.Deserialize(Settings.Default.RootLayout);
            }
        }

        [Command]
        public void OpenDocument() {
            var document = DocumentManagerService.CreateDocument("DocumentView", null, this);
            document.Id = "Document" + Guid.NewGuid().ToString().Replace("-", "");
            document.DestroyOnClose = false;
            document.Title = "Root Document";
            document.Show();
        }

        #region ISupportLogicalLayout
        public bool CanSerialize {
            get { return true; }
        }

        public IEnumerable<object> LookupViewModels {
            get { return null; }
        }
        #endregion
    }
}

#Inheritance

Show 11 items
Object
DispatcherObject
DependencyObject
Freezable
Animatable
DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
DevExpress.Mvvm.UI.Interactivity.Behavior
DevExpress.Mvvm.UI.Interactivity.Behavior<FrameworkElement>
DevExpress.Mvvm.UI.ServiceBaseGeneric<FrameworkElement>
ServiceBase
LayoutSerializationService
See Also