代码之家  ›  专栏  ›  技术社区  ›  Saghar

使用codeplex中的LocalizationExtension搜索变通方法以在Ribbon控件上应用本地化

  •  1
  • Saghar  · 技术社区  · 15 年前

    http://wpflocalizeextension.codeplex.com/

        <MvvmCore:RibbonCommandExtended x:Key="SwitchLanguageCommand" 
                                CanExecute="RibbonCommandExtended_CanExecute"
                                Executed="RibbonCommandExtended_Executed"
                                LabelTitle="{lex:LocText Key=SwitchLanguage,Dict=LanRes}"
                                ToolTipTitle="{lex:LocText Key=SwitchLanguage,Dict=LanRes}"
                                LargeImageSource="{lex:LocImage Key=ChangeLanguage,Dict=LanRes}"/>
    

    <rb:RibbonButton x:Name="EnglishButton" Command="{StaticResource SwitchToEnglishCommand}" Click="EnglishButton_Click">
    

    这是我的RibbonCommand扩展类。

     public class RibbonCommandExtended : RibbonCommand
        {
            private ICommand m_command;
            public ICommand Command
            {
                get { return m_command; }
                set
                {
                    m_command = value;
                    if (m_command != null)
                    {
                        this.CanExecute += UsCanExecute;
                        this.Executed += UsExecuted;
                    }
                    else
                    {
                        this.CanExecute -= UsCanExecute;
                        this.Executed -= UsExecuted;
                    }
                }
            }
    
            private void UsExecuted(object sender, ExecutedRoutedEventArgs e)
            {
                Command.Execute(e.Parameter);
            }
    
            private void UsCanExecute(object sender, CanExecuteRoutedEventArgs e)
            {
                e.CanExecute = Command.CanExecute(e.Parameter);
            }
        }
    

    当我的程序启动时,ribbon控件会选择正确的语言字符串和图像。但是当我在运行时更改语言时,我在功能区控件本地化的文本和图像中看不到任何更改。因为RibbonCommand的LabelTitle、LargeImageSource和所有其他属性都不是依赖属性。

    已经有人解决这个问题了吗?或者除了本地化扩展之外,还有其他方法可以使我的应用程序本地化,从而满足我的需求吗?

    1 回复  |  直到 15 年前
        1
  •  -1
  •   Saghar    15 年前

    使用LocalizationExtension对应用程序进行本地化很容易。但也许,我们应该回到基本的方法去做本地化,分离文化资源并在运行时改变它。请参阅 http://msdn.microsoft.com/en-us/library/ms788718.aspx

    线程.CurrentThread.CurrentCulture=新文化信息(…); http://wpflocalization.codeplex.com/