Localize Ribbon Control

Dec 4, 2008 at 9:10 PM
Hi i want to localize the show quick access toolbar and minimize ribbon commands of the RibbonQuickAccessToolbar component is there a way via styling? thanks
May 18, 2009 at 12:36 PM

Hi!

I had the same problem, I did it with a little reflection and extension method:

    public partial class Window1
    {
        public Window1()
        {
            InitializeComponent();
            Loaded += Window1Loaded;
        }

        void Window1Loaded(object sender, RoutedEventArgs e)
        {
            r.QuickAccessToolBar.LocalizeQat("Customize", "Minimize", "Show below", "Show above");
        }
    }

    public static class RibbonExtension
    {
        public static void LocalizeQat(this RibbonQuickAccessToolBar qat
            , string popupTitle
            , string minimizeRibbonText
            , string showBelowTheRibbonText
            , string showAboveTheRibbonText)
        {
            var positionMenuItem = (RibbonMenuItem)qat.GetType()
                .GetField(
                "_menuItemShowQAT",
                BindingFlags.Instance | BindingFlags.NonPublic)
                .GetValue(qat);

            positionMenuItem.Click += (sender, e) =>
                                          {
                                              var menuItem = (RibbonMenuItem)e.Source;
                                             
                                              var showQatOnTop =
                                                  (bool)
                                                  qat.GetType().GetProperty("ShowQuickAccessToolbarOnTop"
                                                  , BindingFlags.Instance | BindingFlags.NonPublic)
                                                      .GetValue(qat, null);
                                             
                                              menuItem.Header = showQatOnTop ? showBelowTheRibbonText : showAboveTheRibbonText;
                                          };

            positionMenuItem.Header = showBelowTheRibbonText;

            var qatDropDownButton = (RibbonDropDownButton)((ContentPresenter)
                qat.Template.FindName("MainCustomizeMenuHost", qat)).Content;

            var qatPopupTitle = (TextBlock)qatDropDownButton.Template.FindName("PART_CustomizeTitle", qatDropDownButton);
            qatPopupTitle.Text = popupTitle;

            var minimizeMenuItem = (RibbonMenuItem)qatDropDownButton.Items[qatDropDownButton.Items.Count - 1];
            minimizeMenuItem.Header = minimizeRibbonText;
        }
    }

Where "r" is the ribbon control in the xaml.

Rolf