在Silverlight中实现本地化 [英] Implementing Localization in Silverlight

查看:95
本文介绍了在Silverlight中实现本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我要求在Silverlight应用中实施本地化。  该解决方案有8个silverlight应用程序,其中一个项目有其他7个引用。所有应用程序都有自己的app.xaml启动文件。

I have requirement of implementing Localization in a silverlight app.  The solution has 8 silverlight applications amongst which one of the project has references of other 7.  All the applications have their invidual app.xaml start up file.

假设我有一个项目Web.ABC,其中包含7个其他项目的参考,并且可以说其中一个是Web.DEF。我在Web.DEF中创建了一个资源文件和一个ResourceWrapper类,并在Web.DEF的App.xaml中声明了一个资源键:

Let's say I have a project Web.ABC which has references of 7 other projects and lets say one of them is Web.DEF. I created a resource file and a ResourceWrapper class in Web.DEF and declare a resource key as below in App.xaml of  Web.DEF :

<local:ResourceWrapper x:Key="ResourceWrapperKey"></local:ResourceWrapper>

在Web.DEF中的一个xaml中我修改如下:

In one of xaml in Web.DEF i modified like below:

<CheckBox      Grid.Row="3" Grid.Column="1" x:FieldModifier="private" x:Name="chkIsMaster" Content="{Binding Path=ApplicationStrings.MyNewString, Source={StaticResource ResourceWrapperKey}}"  HorizontalAlignment="Left"  VerticalAlignment="Center" AutomationProperties.Name="Enabled" />

但问题是,当我运行Application Web.ABC时,选择一个从中调用Web.DEF的选项卡,它会在找不到ResourceWrapperKey时给出错误因为App.xaml没有被调用。

But the issue is that when i run the Application Web.ABC, select a tab from where Web.DEF gets invoked,it gives me error as ResourceWrapperKey not found because the App.xaml does not get invoke.

为了解决这个问题,我在Web.ABC的App.xaml中声明了上面的资源键(因为我在那里引用了Web.DEF)和参考Web.DEF中存在的ResourceWrapper,如下所示:

To fix this I declare the above resource key in App.xaml of Web.ABC (as i have reference of Web.DEF there) and reffered to the ResourceWrapper present in Web.DEF as below:

<Application x:Class="Controllers.CMApplication"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
             xmlns:local="clr-namespace:Controller;assembly=Web.DEF">
<Application.Resources>
                <local:ResourceWrapper x:Key="ResourceWrapperKey"></local:ResourceWrapper>
    </Application.Resources>
</Application>




但我不确定如何在此处引用此密钥Web.DEF的xaml内容,因为它不包含Web.ABC的引用。

But I am not sure how would i refer this key in the xaml content of Web.DEF, as it does not contain reference of Web.ABC.

<CheckBox      Grid.Row="3" Grid.Column="1" x:FieldModifier="private" x:Name="chkIsMaster" Content="{Binding Path=ApplicationStrings.MyNewString, Source={StaticResource ResourceWrapperKey}}"  HorizontalAlignment="Left"  VerticalAlignment="Center" AutomationProperties.Name="Enabled" />

请帮帮我。

谢谢&问候。

Thanks & Regards.

Abdeali

推荐答案



您应该创建一个新的WPF自定义控件库/ Silverlight类库项目,然后在那里添加ResourceWrapper类和包含ResourceWrapperKey资源的ResourceDictionary(Dictionary1.xaml) 


You should create a new WPF Custom Control Library / Silverlight Class Library project and in there you add the ResourceWrapper class and a ResourceDictionary (Dictionary1.xaml) containing the ResourceWrapperKey resource:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 <local:ResourceWrapper x:Key="ResourceWrapperKey"></local:ResourceWrapper>
</ResourceDictionary>

现在,在所有其他将使用此资源的项目中,添加对新控件库的引用,并将ResourceDictionary添加到< Application.Resources>中的ResourceDictionary的MergedDictionaries属性中。在App.xaml中:

Now, in all other projects that will use this resource, you add a reference to the new control library and add the ResourceDictionary to the MergedDictionaries property of the ResourceDictionary in <Application.Resources> in App.xaml:

<Application x:Class="WpfApplication1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
  <ResourceDictionary>
   <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/WpfCustomControlLibrary2;component/Dictionary1.xaml"/>
   </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
 </Application.Resources>
</Application>

请注意,您需要替换"WpfCustomControlLibrary2"。具有控制库组件的名称和"Dictionary1"的名称。使用资源字典的名称来定义ResourceWrapperKey资源。

Note that you need to replace "WpfCustomControlLibrary2" with the name of the control library assembly and "Dictionary1" with the name of the resource dictionary in which the ResourceWrapperKey resource is defined.


这篇关于在Silverlight中实现本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆