Back to Devexpress

LayoutControl.WriteElementToXML Event

wpf-devexpress-dot-xpf-dot-layoutcontrol-dot-layoutcontrol-1990d63e.md

latest3.6 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Wpf.LayoutControl

Declaration

csharp
public event EventHandler<LayoutControlWriteElementToXMLEventArgs> WriteElementToXML
vb
Public Event WriteElementToXML As EventHandler(Of LayoutControlWriteElementToXMLEventArgs)

Event Data

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

PropertyDescription
ElementGets the layout element being written to a data store.
XmlGets 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.

csharp
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

ReadElementFromXML

ReadFromXML(XmlReader)

WriteToXML(XmlWriter)

Save and Restore Item Layout

LayoutControl Class

LayoutControl Members

DevExpress.Xpf.LayoutControl Namespace