Skip to main content

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.1.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