Current filter:
                                You should refresh the page.
                                  • Hello,
                                    I'm trying to create a reusable toolbar as UserControl, that also supports saving the layout. Some of my view might need to add a few more buttons, so I'm using BarAction to add, remove and update the standard toolbar. Since I'm saving and restoring the layout, I need to use the BarManager.

                                    Now here's the issue: inserting new BarButtonItems into the toolbar, does not add them to the customization window tab "Commands". Run the attachted sample to see, that "MyNewlyAddedButton" does not appear in the customization window.

                                    If I were to just use a ToolBarControl in my UserControl, this would work fine, but then I couldn't save and restore my layout.

                                    So my question is how do I add the inserted BarButtonItems to the custimazation window? Or alternatively how do I save the layout of a ToolBarControl?
                                    Either one would solve my problem.

                                    Thanks in advance.


                                    (I omitted the saving and restoring part from the sample.)

                                1 Solution

                                Creation Date Importance Sort by

                                Hello,
                                The cause of this behavior is that this inserted BarItem isn't initially defined in the same BarManager. To change this behavior and display it, it's necessary to create an AllItemsBarManagerCategory class descendant and override its GetBarItems method in the following manner to allow search for bar items in the BarManager scope's ancestors:

                                [VB.NET]
                                Public Class BarManagerCategoryEx Inherits AllItemsBarManagerCategory Public Sub New(skipNameCheck As Boolean, name As String, scopeNode As FrameworkElement, isSpecialCategory As Boolean, caption As String) Me.SkipNameCheck = skipNameCheck Me.Name = name Me.ScopeNode = scopeNode Me.IsSpecialCategory = isSpecialCategory Me.Caption = caption End Sub Public Property SkipNameCheck() As Boolean Public Overrides Function GetBarItems() As List(Of BarItem) Return _ BarNameScope.GetService (Of IElementRegistratorService)(ScopeNode).GetElements (Of BarItem)( ScopeSearchSettings.Local Or ScopeSearchSettings.Ancestors).Where( function(item) SkipNameCheck Or Name.Equals(item.CategoryName)).ToList() End Function End Class


                                After that, use this class descendant to override BarManager's default categories:

                                [VB.NET]
                                Public Class BarManagerEx Inherits BarManager Protected Overrides Sub OnLoaded(sender As Object, e As EventArgs) MyBase.OnLoaded(sender, e) Dim categories = Me.Categories.Wrap(Of IBarManagerCategoryCollectionWrapper)() categories.allItems = New BarManagerCategoryEx(True, "All Items", Me, true, BarsLocalizer.GetString(BarsStringId.BarManagerCategory_AllItemsCategoryCaption)) categories.unassignedItems = New BarManagerCategoryEx(False, "Unassigned Items", Me, true, BarsLocalizer.GetString(BarsStringId.BarManagerCategory_UnassignedCategoryCaption)) End Sub End Class

                                I've modified the sample project to demonstrate the main idea of this approach.

                                Thanks,
                                Kirill

                                • Nick H. 01.12.2019
                                  Hello,
                                  thanks a lot, this solves this issue.

                                  I have two related questions though:

                                  1. It seems CategoryNames are not working. How can I fix this?
                                  2. In some views the Actions are not triggering. So I just end up with the default toolbar layout. Do you have any idea why?

                                  To expand on that, in general the views are just usercontrols that get added to a DXTabControl (via prism), when the user clicks a button. For most views we use a custom HeaderedContentControl that also contains an area for our toolbars (a Contentpresenter with a FrameworkElement as source).

                                  When I put the toolbar in that area, all the actions trigger fine on the loaded event. But if I'm not using the custom HeaderedContentControl, so the toolbar is just in a usercontrol, the actions won't trigger. Do you have any idea why this might be the case?

                                  Thanks again for always working so fast.

                                  Have a nice day!
                                • Andrey Marten (DevExpress Support) 01.14.2019


                                  Hello Nick,

                                  I do not see categories defined in your bar items in the project either. To resolve this issue, you can use the approach I illustrated at T400921 and generate these categories based on values in your BarItems. I've updated the project accordingly. Please refer to the attachment. Categories and their order are defined in BarManagerEx's GetCategories method. This method is called by the MyCustomizationHelper class in its InitializeCategories method. Please test this approach in your application and let me know your results. 

                                  As for your second question, I'm afraid the provided information is insufficient to determine the cause of the issue. I'd appreciate it if you create a separate ticket for this issue and provide a simple sample showing the same issue. This will help us find the cause of this behavior and suggest a more suitable solution. 

                                  Thanks,
                                  Andrey