转载

Telerik 控件的汉化-检索当前控件的键值对

(第一次随手写了个东东发现被各种转载,傻笑下,那就顺便把下午试验出来的方式给大家分析下吧,妹纸说难得被转载一次,鼓励我多写点)

telerik每个版本内置的英文是有差异的,然后很多资料的内置键值对都是不全的,下面的方法是用来查询当前控件的所有键值对.

这个是借鉴资料山寨来的思路.

核心思路其实就是新增一个继承LocalizationManager,CustomLocalizationManager类,然后重写这个类的语言的时候获取出所有键值对.

1.新建一个CustomLocalizationManager类,用来注入当前你想获取键值对的控件.

在工程起始加载自定义汉化类

/// <summary>  /// Interaction logic for App.xaml  /// </summary>  public partial class App : Application  {   public App()   {    LocalizationManager.Manager = new CustomLocalizationManager();   }  } 
public class CustomLocalizationManager : LocalizationManager  {   public override string GetStringOverride(string key)   {    //switch (key)    //{    // case "JudgementCode":    //  return "Your translation";    //}    if (!dataKeys.dic.ContainsKey(key))    {     DataKeys.dic.Add(key, base.GetStringOverride(key));    }    return base.GetStringOverride(key);    }  } 

增加一个Dictionary 类用来记录键值对:

public static class DataKeys     {         public static Dictionary<string, string> dic = new Dictionary<string, string>();     }

2. 加载一个你想汉化的telerik控件如:(注意把LocalizationManager 类注入到控件内部)

<telerik:RadGridView Grid.Row="0"                               AutoGenerateColumns="False"                              Margin="5">    <telerik:RadGridView.Columns>                 <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}">                     <telerik:GridViewDataColumn.Header>                         <TextBlock telerik:LocalizationManager.ResourceKey="JudgementCode"></TextBlock>                     </telerik:GridViewDataColumn.Header>                 </telerik:GridViewDataColumn>    </telerik:RadGridView.Columns>         </telerik:RadGridView>

然后就没有然后了...编译通过,然后调试下DataKeys.dic,里面记录了所有的键值对(删了测试的键值JudgementCode),再根据我上一篇文章说的方式,加载本地化资源文件...Over

DataKeys.dic 值如下:

KEYS:

CommitEdit CommitCellEdit BeginEdit BeginInsert CancelCellEdit CancelRowEdit Copy Delete MoveLeft MoveRight MoveUp MoveDown MoveNext MovePrevious MoveFirst MoveLast MoveHome MoveEnd MovePageDown MovePageUp MoveTop MoveBottom Paste SelectCurrentItem SelectCurrentUnit ExtendSelectionToCurrentUnit ActivateRow ExpandHierarchyItem CollapseHierarchyItem JudgementCode GridViewGroupPanelText GridViewGroupPanelTopTextGrouped

VALUES:

Commit Edit CommitCellEdit Begin Edit Begin Insert Cancel Cell Edit Cancel Row Edit Copy Delete Move Left Move Right Move Up Move Down Move Next Move Previous Move First Move Last Move Home Move End Move PageDown Move PageUp Move Top Move Bottom Paste Select Current Item Select the current unit Extends selection to current unit Activate Expand Collapse  Drag a column header and drop it here to group by that column Grouped by:
正文到此结束
Loading...