Access the Dashboard Control
- 2 minutes to read
This topic describes how to access the DashboardViewer control in a WinForms application and the DxDashboard component model in an ASP.NET Core Blazor application.
Note
Refer to the following help topic for information on how to access the DashboardDesigner control: How to: Access the WinForms Dashboard Designer.
Important
Before you proceed, ensure that your platform-specific application project references the corresponding assemblies or NuGet packages:
- WinForms: the DevExpress.Dashboard.v25.2.Win.dll and DevExpress.ExpressApp.Dashboards.Win.v25.2.dll assemblies;
- ASP.NET Core Blazor: the DevExpress.ExpressApp.Dashboards.Blazor.25.2 NuGet package.
ASP.NET Core Blazor Applications
To access the DxDashboard component model, follow the steps below in the ASP.NET Core Blazor application project (MySolution.Blazor.Server) and WinForms application project (MySolution.Win). A component model defines a Blazor component in code. When you modify the model, the underlying component reflects these changes. Refer to the following help topic for more information on component models: Underlying Controls and Components Behind UI Elements (ASP.NET Core Blazor).
- Add a Controller activated in the Dashboard Views.
- In the Controller’s
OnActivatedmethod, use the CustomizeViewItemControl<T>(DashboardView, Controller, Action<T>) extension method to customize theBlazorDashboardViewerViewItembefore the DxDashboard component is rendered. - In the
CustomizeViewItemControlmethod access theBlazorDashboardViewerViewItem.ComponentModelproperty (in ASP.NET Core Blazor applications) orWinDashboardViewerViewItem.Viewer(in Windows Forms applications).
The following code snippet sets the default dashboard working mode to Designer:
File:
MySolution.Blazor.Server\Controllers\BlazorDashboardController.cs
using DevExpress.DashboardWeb;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Blazor.Components;
using DevExpress.Persistent.Base;
namespace MySolution.Blazor.Server.Controllers;
public class BlazorDashboardController : ViewController<DashboardView> {
protected override void OnActivated() {
base.OnActivated();
View.CustomizeViewItemControl<BlazorDashboardViewerViewItem>(this, item => {
item.ComponentModel.WorkingMode = WorkingMode.Designer;
});
}
}
Tip
To access and customize Dashboard View Item controls, use the CustomizeViewItemControl<T>(DashboardView, Controller, Action<T>) method.
The following code snippet enables Dashboard data printing:
WinForms
File:
MySolution.Win\Controllers\WinDashboardController.cs
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Dashboards.Win;
namespace MainDemo.Win.Controllers;
public class WinDashboardController : ViewController<DashboardView> {
protected override void OnActivated() {
base.OnActivated();
View.CustomizeViewItemControl<WinDashboardViewerViewItem>(this, item => {
if (item.Control != null) {
var dashboardViewer = ((WinDashboardViewerViewItem)item).Viewer;
if (dashboardViewer != null) {
dashboardViewer.AllowPrintDashboardItems = true;
}
}
});
}
}