WinForms skin choosers: using your own skin names

ctodx
22 October 2010

In the recent couple of blog posts on the new skin chooser that’s coming up in v2010 vol. 2, there were many comments about requiring the need to change the names of the skins we provide in WinForms. For some unknown reason ;), the example name that came up most often was “DevExpress Style”, although we are in negotiations with Nike to use it in their new Spring collection.

Anyway, no sooner than the requests started to come in that the team implemented support for it in v2010.2. Well, actually, they merged it into the localization support for the bars library, but it works extremely well for just “renaming” certain skins.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraBars.Localization;

namespace HowToUseBarSkinHelper {
    public partial class Form1 : RibbonForm {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            BarLocalizer.Active = new MyBarLocalizer();

            SkinHelper.InitSkinGallery(ribbonGalleryBarItem1, true);
            SkinHelper.InitSkinPopupMenu(popupMenu1);
        }
    }

    // Custom localizer that changes skin captions 
    public class MyBarLocalizer : BarLocalizer {
        public override string GetLocalizedString(BarString id) {
            if (id == BarString.SkinCaptions) {
                //Default value for BarString.SkinCaptions:
                //"|DevExpress Style|Caramel|Money Twins|The Asphalt World|..."
                string defaultSkinCaptions = base.GetLocalizedString(id);
                string newSkinCaptions = 
                        defaultSkinCaptions.Replace("|DevExpress Style|", "|My Hip Style|");
                return newSkinCaptions;
            }
            return base.GetLocalizedString(id);
        }
    }
}

Here, you can see that we make use of the BarLocalizer.Active property to set an instance of a special localizer class. This class overrides the GetLocalizedString method to look out for the new BarString.SkinCaptions enum value and if found to replace "|DevExpress Style|" with "|My Hip Style|" in the default skin captions string (this string is a pipe delimited string of skin names, in a particular fixed order).

And that’s it, really. Nice and neat. Incidentally in the code you can see the use of the new SkinHelper class to populate an existing RibbonGalleryBarItem or any menu (PopupMenu or SubMenu) with items that correspond to the DevExpress skins.

(Aside: this blog post is taken from a new knowledgebase example E2523 which will be published with the release of v2010.2.)

OK, I admit it. I was joking about Nike.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.