Current filter:
                                You should refresh the page.
                                  • Hi XAF Support.
                                    I have a application where I want to hide certain Navigation Groups at startup of my Win Application. At this point I am leading on reading a value the the app.config file which will determine which Navigation groups to hide or display. Can you provide me with a code snippet or simple example that shows me how to implement this functionality.

                                1 Solution

                                Creation Date Importance Sort by

                                Hello Bernard,
                                Please refer to the following thread on our forum, where a solution on how to hide navigation items in the navigation panel is discussed: How to remove navigation item
                                Here is also some working example code for your reference:

                                using System; using DevExpress.ExpressApp; using System.Collections.Generic; using DevExpress.ExpressApp.Actions; using DevExpress.ExpressApp.SystemModule; using DevExpress.ExpressApp.Security.Strategy; namespace YourSolutionName.Module { public class HideItemWindowController : WindowController { private ShowNavigationItemController navigationController; public HideItemWindowController() { TargetWindowType = WindowType.Main; } protected override void OnFrameAssigned() { base.OnFrameAssigned(); navigationController = Frame.GetController<ShowNavigationItemController>(); if(navigationController != null) { navigationController.ItemsInitialized += new EventHandler<EventArgs>(HideItemWindowController_ItemsInitialized); } } protected override void OnDeactivated() { if(navigationController != null) { navigationController.ItemsInitialized -= new EventHandler<EventArgs>(HideItemWindowController_ItemsInitialized); navigationController = null; } base.OnDeactivated(); } private void HideItemWindowController_ItemsInitialized(object sender, EventArgs e) { SecuritySystemUser currentUser = SecuritySystem.CurrentUser as SecuritySystemUser; if(currentUser != null) { foreach(SecuritySystemRole role in currentUser.Roles) { if(role.Name == "Users") { HideItemByCaption(navigationController.ShowNavigationItemAction.Items, "Reports"); } } } } private void HideItemByCaption(ChoiceActionItemCollection items, string navigationItemId) { foreach(ChoiceActionItem item in items) { if(item.Id == navigationItemId) { item.Active["InactiveForUsersRole"] = false; return; } HideItemByCaption(item.Items, navigationItemId); } } } }
                                Imports System Imports DevExpress.ExpressApp Imports System.Collections.Generic Imports DevExpress.ExpressApp.Actions Imports DevExpress.ExpressApp.SystemModule Imports DevExpress.ExpressApp.Security.Strategy Namespace YourSolutionName.Module Public Class HideItemWindowController Inherits WindowController Private navigationController As ShowNavigationItemController Public Sub New() TargetWindowType = WindowType.Main End Sub Protected Overrides Sub OnFrameAssigned() MyBase.OnFrameAssigned() navigationController = Frame.GetController(Of ShowNavigationItemController)() If navigationController IsNot Nothing Then AddHandler navigationController.ItemsInitialized, AddressOf HideItemWindowController_ItemsInitialized End If End Sub Protected Overrides Sub OnDeactivated() If navigationController IsNot Nothing Then RemoveHandler navigationController.ItemsInitialized, AddressOf HideItemWindowController_ItemsInitialized navigationController = Nothing End If MyBase.OnDeactivated() End Sub Private Sub HideItemWindowController_ItemsInitialized(ByVal sender As Object, ByVal e As EventArgs) Dim currentUser As SecuritySystemUser = TryCast(SecuritySystem.CurrentUser, SecuritySystemUser) If currentUser IsNot Nothing Then For Each role As SecuritySystemRole In currentUser.Roles If role.Name = "Users" Then HideItemByCaption(navigationController.ShowNavigationItemAction.Items, "Reports") End If Next role End If End Sub Private Sub HideItemByCaption(ByVal items As ChoiceActionItemCollection, ByVal navigationItemId As String) For Each item As ChoiceActionItem In items If item.Id = navigationItemId Then item.Active("InactiveForUsersRole") = False Return End If HideItemByCaption(item.Items, navigationItemId) Next item End Sub End Class End Namespace

                                Let me know in case of any difficulty when implementing this.
                                Check if Search Engine is able to answer questions faster than I do!

                                Show all comments
                                • Dennis (DevExpress) 03.17.2009

                                  Welcome, Bernard! ;-)

                                • shiela p 09.30.2014

                                  Is this the same implementation for web?

                                • Dennis (DevExpress) 09.30.2014

                                  @shiela: Yes.

                                • INFO CL 12.08.2014

                                  An exemple please for the web? I have use the same implementation but not work.

                                • Dennis (DevExpress) 12.09.2014

                                  @INFO CL: This code is platform-agnostic. Please create a new Support Center ticket and attach your test project there for review. Thanks.

                                • Scott Gross 06.26.2016

                                  This worked as expected. Could you possibly add a link to this in the Navigation Module Documentation? would have saved me a good amount of time.

                                • Dennis (DevExpress) 06.27.2016

                                  @Scott: Thanks for your feedback. We will take your suggestion into account.