Back to Devexpress

DashboardControl.SetInitialDashboardState Event

dashboard-devexpress-dot-dashboardwpf-dot-dashboardcontrol-6bfb4270.md

latest7.4 KB
Original Source

DashboardControl.SetInitialDashboardState Event

Allows you to specify the initial dashboard state when loading a dashboard.

Namespace : DevExpress.DashboardWpf

Assembly : DevExpress.Dashboard.v25.2.Wpf.dll

NuGet Package : DevExpress.Wpf.Dashboard

Declaration

csharp
public event SetInitialDashboardStateWpfEventHandler SetInitialDashboardState
vb
Public Event SetInitialDashboardState As SetInitialDashboardStateWpfEventHandler

Event Data

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

PropertyDescription
DashboardA dashboard whose state can be initialized. Inherited from SetInitialDashboardStateBaseEventArgs.
InitialStateGets or sets the dashboard initial state. Inherited from SetInitialDashboardStateBaseEventArgs.

Remarks

View Example: How to Set the Initial Dashboard State

This example demonstrates how to manage dashboard state to save and restore selected master filters values, current drill-down levels, and other parameters such as Treemap layers.

When the application starts, the DashboardControl loads the dashboard and the DashboardState object is deserialized and restored using the GetDataFromString method in the DashboardControl.SetInitialDashboardState event handler.

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

namespace WpfDashboard_DashboardState
{
    public partial class MainWindow : Window
    {
        public static readonly string PropertyName = "DashboardState";

        public MainWindow()
        {
            InitializeComponent();
        }

        DashboardState GetDataFromString(string customPropertyValue){
            DashboardState dState = new DashboardState();
            if(!string.IsNullOrEmpty(customPropertyValue)) {
                var xmlStateEl = XDocument.Parse(customPropertyValue);
                dState.LoadFromXml(xmlStateEl);
            }
            return dState;
        }

        private void dashboardControl_SetInitialDashboardState(object sender, DevExpress.DashboardWpf.SetInitialDashboardStateWpfEventArgs e){
            var state = GetDataFromString(dashboardControl.Dashboard.CustomProperties.GetValue(PropertyName));
            e.InitialState = state;
        }
     }
}       
//...
vb
Imports DevExpress.DashboardCommon
Imports System
Imports System.Windows
Imports System.Xml.Linq

Namespace WpfDashboard_DashboardState
    Partial Public Class MainWindow
        Inherits Window
        Public Shared ReadOnly PropertyName As String = "DashboardState"

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Function GetDataFromString(ByVal customPropertyValue As String) As DashboardState
            Dim dState As New DashboardState()
            If (Not String.IsNullOrEmpty(customPropertyValue)) Then
                Dim xmlStateEl = XDocument.Parse(customPropertyValue)
                dState.LoadFromXml(xmlStateEl)
            End If
            Return dState
        End Function

        Private Sub dashboardControl_SetInitialDashboardState(ByVal sender As Object, ByVal e As DevExpress.DashboardWpf.SetInitialDashboardStateWpfEventArgs)
            Dim state = GetDataFromString(dashboardControl.Dashboard.CustomProperties.GetValue(PropertyName))
            e.InitialState = state
        End Sub
    End Class
End Namespace
'...

For more information about a dashboard state, refer to the Manage Dashboard State document.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetInitialDashboardState event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-dashboard-how-to-set-initial-dashboard-state/CS/WpfDashboard_DashboardState/MainWindow.xaml#L20

xml
DashboardSource="SampleDashboardWithState.xml"
        SetInitialDashboardState="dashboardControl_SetInitialDashboardState"/>
</Grid>

wpf-dashboard-how-to-set-initial-dashboard-state/CS/WpfDashboard_DashboardState/obj/Debug/net8.0-windows/MainWindow.g.cs#L107

csharp
#line 20 "..\..\..\MainWindow.xaml"
this.dashboardControl.SetInitialDashboardState += new DevExpress.DashboardWpf.SetInitialDashboardStateWpfEventHandler(this.dashboardControl_SetInitialDashboardState);

wpf-dashboard-how-to-set-initial-dashboard-state/VB/WpfDashboard_DashboardState/obj/Debug/net8.0-windows/MainWindow.g.vb#L105

vb
#ExternalSource("..\..\..\MainWindow.xaml",20)
AddHandler Me.dashboardControl.SetInitialDashboardState, New DevExpress.DashboardWpf.SetInitialDashboardStateWpfEventHandler(AddressOf Me.dashboardControl_SetInitialDashboardState)

See Also

SetDashboardState(DashboardState)

GetDashboardState()

DashboardStateChanged

Manage Dashboard State in the WPF Viewer Control

DashboardControl Class

DashboardControl Members

DevExpress.DashboardWpf Namespace