WinForms skin choosers: using your own skin names

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.

4 comment(s)
Neal

Thanks DX, Mike, et al

22 October, 2010
George Shubin

Coolness!

22 October, 2010
Michael Proctor [DX-Squad]

Looks forward to looking into the skinhelper and the localizer.

Can't wait to try and implement all this stuff into my app.

22 October, 2010
Howard Herrera

Thanks for listening guys.

23 October, 2010

Please login or register to post comments.