Ticket Q557512
Visible to All Users

The best way to create ribbon page group and categories in XAF application

created 11 years ago

Hi!
I need to create ribbon page groups and some ribbon categories too. I was using templates as suggested here https://www.devexpress.com/Support/Center/Question/Details/Q454345, but in my last post https://www.devexpress.com/Support/Center/Question/Details/Q556866 Dennis told that this was not a good idea and told me to create a new ticket for it.
So my question is: what is the best way to organize my actions in custom ribbon groups and categ ories?
Thanks

Comments (1)
Dennis Garavsky (DevExpress) 11 years ago

    Hello Edilson,
    Templates customization usually requires more maintenance effort than customizing the ribbon control in code. I will provide more information on this as soon as I can.

    Answers approved by DevExpress Support

    created 10 years ago (modified 10 years ago)

    In XAF v14.2, you can customize Ribbon form templates within the designer (see New Ribbon Templates for WinForms). Refer to the How to: Create a Custom WinForms Ribbon Template topic for additional information.

      Comments (2)

        That was great!!!

        Dennis Garavsky (DevExpress) 10 years ago

          We are happy to hear that you liked it.

          created 11 years ago (modified 7 years ago)

          This answer applies to old XAF versions. Starting with version 14.2, we introduced new templates that provide convenience design-time customization capabilities. We suggest using the solution provided in the first answer if you are using the latest XAF version.

          There are two possible approaches for adding custom Ribbon pages and categories:

          1. Via templates customization as per Custom action containerAdding a dynamic Reports menu to the main window menu;
          2. Via code;
            Each of them requires different coding, configuration and maintenance efforts. In my opinion, customizing the ribbon control in code seems to be easier and requires less work. You can consider the following WindowController that works for the main application window and adds a custom Ribbon page with a group and a couple of items:
          C#
          using System; using System.Linq; using DevExpress.XtraBars; using DevExpress.ExpressApp; using DevExpress.XtraBars.Ribbon; using System.Collections.Generic; using DevExpress.ExpressApp.Win.Templates; using DevExpress.ExpressApp.Win.Templates.ActionContainers; namespace MainDemo.Module.Win.Controllers { public class Class1 : WindowController{ private XtraFormTemplateBase template; public Class1() { TargetWindowType = WindowType.Main; } protected override void OnActivated() { base.OnActivated(); Window.TemplateChanged += new EventHandler(Window_TemplateChanged); } protected override void OnDeactivated() { Window.TemplateChanged -= new EventHandler(Window_TemplateChanged); if(template != null && template.RibbonTransformer != null) { template.RibbonTransformer.Transformed -= new EventHandler<EventArgs>(RibbonTransformer_Transformed); template = null; } base.OnDeactivated(); } void Window_TemplateChanged(object sender, EventArgs e) { template = ((Window)sender).Template as XtraFormTemplateBase; if(template != null) { template.RibbonTransformer.Transformed += new EventHandler<EventArgs>(RibbonTransformer_Transformed); } } void RibbonTransformer_Transformed(object sender, EventArgs e) { RibbonControl ribbon = ((ClassicToRibbonTransformer)sender).Ribbon; ribbon.BeginInit(); //Dennis: Based on the code from: http://documentation.devexpress.com/#WindowsForms/clsDevExpressXtraBarsRibbonRibbonPagetopic // Create a new page and add it to the ribbon. RibbonPage ribbonPage = new RibbonPage("Format"); ribbon.Pages.AddRange(new RibbonPage[] { ribbonPage }); // Customize the Format page by adding a Format group with two bar items to it. RibbonPageGroup ribbonPageGroup = new RibbonPageGroup("Format"); ribbonPageGroup.AllowTextClipping = false; // Add two items to the Format group BarButtonItem itemCopy = new BarButtonItem(ribbon.Manager, "Copy", 0); BarButtonItem itemCut = new BarButtonItem(ribbon.Manager, "Cut", 1); ribbonPageGroup.ItemLinks.AddRange(new BarItem[] { itemCopy, itemCut }); ribbonPage.Groups.Add(ribbonPageGroup); ribbon.EndInit(); } } }

          Please refer to the XtraBars documentation to learn more about possible ribbon customizations.

            Show previous comments (4)
            Dennis Garavsky (DevExpress) 10 years ago

              @Alex:
              >>I would prefer to generate the extra ribbon items by code.
              Please create a separate ticket in the Support Center and elaborate more on your business requirements and scenario so we could provide you with the best technical solution for it. You are correct that you need a different mechanism with the V2 templates.

                @Dennis:
                Done. See T202628
                Thx

                Dennis Garavsky (DevExpress) 10 years ago

                  @Alex: Much appreciated!

                  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.