Blogs

This Blog

News

Favorite Posts

Archives

ctodx

Discussions, news and rants from the CTO of DevExpress, Julian M Bucknall

WinForms skin choosers: using your own skin names

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.

Published Oct 22 2010, 11:33 AM by
Bookmark and Share

Comments

Neal

Thanks DX, Mike, et al

October 22, 2010 2:54 PM

George Shubin

Coolness!

October 22, 2010 3:00 PM

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.

October 22, 2010 11:45 PM

Howard Herrera

Thanks for listening guys.

October 23, 2010 11:04 PM

About Julian Bucknall (DevExpress)

Julian is the Chief Technology Officer at Developer Express. You can reach him directly at julianb@devexpress.com. You can also follow him on Twitter with the ID JMBucknall.
LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2014 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners