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

LayoutControl.WriteElementToXML Event

Allows you to save custom properties of layout groups and their children when saving layouts.

Namespace: DevExpress.Xpf.LayoutControl

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

NuGet Package: DevExpress.Wpf.LayoutControl

#Declaration

#Event Data

The WriteElementToXML event's data class is LayoutControlWriteElementToXMLEventArgs. The following properties provide information specific to this event:

Property Description
Element Gets the layout element being written to a data store.
Xml Gets an XMLWriter object that implements saving XML data.

#Remarks

When saving/loading layouts to a data store, only properties that can be changed by an end-user during layout customization are stored/restored. If you need to save/load custom properties, handle the WriteElementToXML and LayoutControl.ReadElementFromXML events.

These events are useful if you allow users to change specific properties of layout items/groups, and want these changes to be saved/loaded when the layout is saved/loaded.

The following code shows how you can save/load the FontSize property for LayoutItem objects to a data store.

using DevExpress.Xpf.LayoutControl;
using DevExpress.Xpf.Core.Native;

private void layoutControl1_WriteElementToXML(object sender, DevExpress.Xpf.LayoutControl.LayoutControlWriteElementToXMLEventArgs e) {
    if (typeof(LayoutItem).IsAssignableFrom(e.Element.GetType())) {
        e.Element.WritePropertyToXML(e.Xml, LayoutItem.FontSizeProperty, "FontSize");
    }
}

private void layoutControl1_ReadElementFromXML(object sender, DevExpress.Xpf.LayoutControl.LayoutControlReadElementFromXMLEventArgs e) {
    if (typeof(LayoutItem).IsAssignableFrom(e.Element.GetType())) {
        e.Element.ReadPropertyFromXML(e.Xml, LayoutItem.FontSizeProperty, "FontSize", typeof(double));
    }
}

Note

WritePropertyToXML and ReadPropertyFromXML are extension methods declared in the DevExpress.Xpf.Core.Native namespace. To use these methods, ensure that this namespace is added to your unit.

See Also