How To: Localize Bar and Ribbon Skin Items

  • 2 minutes to read

You can utilize a Localizer object to customize skin menus, instead of iterating through each Bar skin sub-menu item and Ribbon skin gallery item container to manually modify the items. This approach allows you to customize skin items in all existing bar sub-menus and Ribbon galleries at once.

  1. Create a BarLocalizer class descendant and override its virtual XtraLocalizer<T>.GetLocalizedString method.

    
    public class MyBarLocalizer : BarLocalizer {
        public override string GetLocalizedString(BarString id) {
            if(id == BarString.SkinCaptions) {
                string defaultSkinCaptions = base.GetLocalizedString(id);
                string newSkinCaptions = defaultSkinCaptions.Replace("|DevExpress Style|", "|Default Skin|");
                newSkinCaptions = newSkinCaptions.Replace("|DevExpress Dark Style|", "|Default Dark Skin|");
                return newSkinCaptions;
            }
            return base.GetLocalizedString(id);
        }
    }
    
  2. Use the static BarLocalizer.Active property to set a new instance of your custom class as the current bar localizer. Call this method in the Program class before the Application.Run method call, as shown below.

    
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            BonusSkins.Register();
            SkinManager.EnableFormSkins();
            BarLocalizer.Active = new MyBarLocalizer();
            Application.Run(new Form1());
        }
    }
    
  3. Run the application to see the result.

    Skins - Custom Bar Skin Subitem 2

IMPORTANT

If the custom localizer is assigned after a bar skin sub item, or if the Ribbon skin gallery is already initialized (e.g., on the Load event), skin items will display default captions. In this case, call static SkinHelper.InitSkinPopupMenu and SkinHelpber.InitSkinGallery methods to initialize skin items again and activate the localizer.


void ucBar_Load(object sender, EventArgs e) {
    BarLocalizer.Active = new MyBarLocalizer();
    //refresh bar sub-item links
    skinBarSubItem1.ClearLinks();
    SkinHelper.InitSkinPopupMenu(skinBarSubItem1);
    //refresh Ribbon gallery links
    SkinHelper.InitSkinGallery(skinRibbonGalleryBarItem1);
}
See Also