0

我们的应用程序支持多语言,但 radribbon 存在问题。

我们使用此代码更改语言,除了功能区之外它可以工作

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(langCode);
        SuspendLayout();
        ComponentResourceManager manager = new ComponentResourceManager(this.GetType());
        manager.ApplyResources(this, "$this");
        ApplyResources(manager, this.Controls);
        ResumeLayout();



private void ApplyResources(ComponentResourceManager manager,Control.ControlCollection ctls)
        {

            //all controls
            foreach (Control ctl in ctls)
            {
                manager.ApplyResources(ctl, ctl.Name);
                Trace.WriteLine("Control: " + ctl.GetType().ToString());
                ApplyResources(manager, ctl.Controls);
            }
        }

问题是ribbonbar没有孩子。选项卡位于 CommandTabs 集合中,并且项目不是由 windows.controls 派生的。

那我应该用什么?

4

1 回答 1

0

我解决了这个问题,它有点脏,但它对我有用

  private void ApplyResources(ComponentResourceManager manager, object controls)
    {
        if (controls is Control.ControlCollection)
        {
            var ctls = (Control.ControlCollection)controls;
            //all controls
            foreach (Control ctl in ctls)
            {

                if (ctl is RadRibbonBar)
                {
                    var tabs = ((RadRibbonBar)ctl).CommandTabs;
                    foreach (RibbonTab tab in tabs)
                    {
                        manager.ApplyResources(tab, tab.Name);
                        ApplyResources(manager, tab.Items);
                    }

                }
                else
                {
                    manager.ApplyResources(ctl, ctl.Name);
                    ApplyResources(manager, ctl.Controls);
                }
            }
        }
        else // if (controls is RadItemOwnerCollection)
        {
            var elementCollection = controls as RadItemOwnerCollection;


            foreach (var elem in elementCollection)
            {
                if (elem is RadRibbonBarGroup)
                {
                    var barGroup = elem as RadRibbonBarGroup;
                    manager.ApplyResources(barGroup, barGroup.Name);
                    ApplyResources(manager, barGroup.Items);
                }
                else if (elem is RadRibbonBarButtonGroup)
                {
                    var btnGroup = elem as RadRibbonBarButtonGroup;
                    manager.ApplyResources(btnGroup, btnGroup.Name);
                    ApplyResources(manager, btnGroup.Items);
                }
                else
                {
                    manager.ApplyResources(elem, elem.Name);

                }
            }
        }


    }
于 2017-04-11T13:17:58.087 回答