Example T1002750
Visible to All Users

XAF - How to show the number of List View items in the Navigation Control

Scenario

In this example, we demonstrate how to show the number of List View items in the Navigation Control. You can add or delete items in List Views. The record count in navigation item captions will be automatically updated.

ASP.NET Core Blazor

image

Implementation Steps

  1. Create a View Controller. In the overridden OnActivated method, handle the IObjectSpace.Committed event. In this event handler, call the ShowNavigationItemController.RecreateNavigationItems method to re-create the Navigation System items after saving changes made in the current Grid List editor.
  2. Create a Window Controller. Handle the ShowNavigationItemController.NavigationItemCreated event in the overridden OnFrameAssigned method. In this event handler, specify the item caption via the e.NavigationItem.Caption property.

Files to look at:

See Also

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

EFCore/ItemCountEF/ItemCountEF.Module/Controllers/RefreshNavigationController.cs
C#
using DevExpress.ExpressApp; using DevExpress.ExpressApp.SystemModule; using dxTestSolution.Module.BusinessObjects; namespace ItemCount.Module.Controllers { public class RefreshNavigationController : ViewController { public RefreshNavigationController() { TargetViewNesting = Nesting.Root; TargetObjectType = typeof(Email); } protected override void OnActivated() { base.OnActivated(); View.ObjectSpace.Committed += ObjectSpace_Committed; } private void ObjectSpace_Committed(object sender, System.EventArgs e) { ShowNavigationItemController controller = Application.MainWindow.GetController<ShowNavigationItemController>(); if(controller != null) { controller.ShowNavigationItemAction.BeginUpdate(); controller.RecreateNavigationItems(); controller.ShowNavigationItemAction.EndUpdate(); } } protected override void OnDeactivated() { View.ObjectSpace.Committed -= ObjectSpace_Committed; base.OnDeactivated(); } } }
EFCore/ItemCountEF/ItemCountEF.Module/Controllers/NavigationObjectCountController.cs
C#
using System; using System.Collections.Generic; using System.Net; using System.Text; using DevExpress.Data.Filtering; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Model; using DevExpress.ExpressApp.SystemModule; using dxTestSolution.Module.BusinessObjects; namespace ItemCount.Module.Controllers { public class NavigationObjectCountController : WindowController { private ShowNavigationItemController navigationController; protected override void OnFrameAssigned() { UnsubscribeFromEvents(); base.OnFrameAssigned(); navigationController = Frame.GetController<ShowNavigationItemController>(); if(navigationController != null) { navigationController.NavigationItemCreated += NavigationItemCreated; } } void NavigationItemCreated(object sender, NavigationItemCreatedEventArgs e) { var lvId = Application.GetListViewId(typeof(Email)); if(e.ModelNavigationItem.Id == lvId) { using(IObjectSpace objectSpace = Application.CreateObjectSpace(typeof(Email))) { IModelListView modelListView = (IModelListView)e.ModelNavigationItem.View; int objectsCount = objectSpace.GetObjectsCount(typeof(Email), CriteriaOperator.Parse(modelListView.Criteria)); e.NavigationItem.Caption = "Inbox" + (objectsCount > 0 ? $" ({objectsCount})" : string.Empty); } } } private void UnsubscribeFromEvents() { if(navigationController != null) { navigationController.NavigationItemCreated -= NavigationItemCreated; navigationController = null; } } protected override void Dispose(bool disposing) { UnsubscribeFromEvents(); base.Dispose(disposing); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.