我们的应用程序支持多语言,但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派生的。
那我该怎么用?
答案 0 :(得分: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);
}
}
}
}