How to: Save and Restore the Dashboard State

  • 2 min to read

This example demonstrates how to manage the dashboard state to save and restore selected master filter values, current drill-down levels and other selections such as the selected Treemap layer.

When the main window closes, the GetDashboardState() method obtains a dashboard state object. It is serialized to XML and added to the XElement object stored in the Dashboard.UserData property. Subsequently, the dashboard with the dashboard state data is saved to a file.

When the application starts, the DashboardControl loads the dashboard and the DashboardState object is deserialized in the DashboardLoaded event handler.

The dashboard state is restored using the SetDashboardState(DashboardState) in the SetInitialDashboardState event handler.


The complete sample project How to Set the Initial Dashboard State is available in the DevExpress Examples repository.

using DevExpress.DashboardCommon;
using DevExpress.DashboardWpf;
using System;
using System.Windows;
using System.Xml.Linq;

namespace WpfDashboard_DashboardState {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        DashboardState dState = new DashboardState(); 
        public MainWindow() {
        private void dashboardControl_DashboardLoaded(object sender, DashboardLoadedEventArgs e) {
            XElement data = e.Dashboard.UserData;
            if (data != null) {
                if (data.Element("DashboardState") != null) {
                    XDocument dStateDocument = XDocument.Parse(data.Element("DashboardState").Value);
        private void dashboardControl_SetInitialDashboardState(object sender, SetInitialDashboardStateWpfEventArgs e) {
            e.InitialState = dState;
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
            dState = dashboardControl.GetDashboardState();
            XElement userData = new XElement("Root", 
                new XElement("DateModified", DateTime.Now), 
                new XElement("DashboardState", dState.SaveToXml().ToString(SaveOptions.DisableFormatting)));
            dashboardControl.Dashboard.UserData = userData;