Windows8 全球资源化

<Page
    x:Class="Metro全球化资源.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Metro全球化资源"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <StackPanel Orientation="Horizontal"  HorizontalAlignment="Center" VerticalAlignment="Center">
            <ComboBox Margin="10, 10, 0, 13" Grid.Column="0"  SelectedValuePath="Tag" Name="lanComboBox"  
                      HorizontalAlignment="Left" VerticalAlignment="Top"
                      Width="106" Height="34" SelectionChanged="langComboBox_SelectionChanged">
                <ComboBoxItem Tag="en-US">English</ComboBoxItem>
                <ComboBoxItem Tag="zh-CN">Chinese</ComboBoxItem>
            </ComboBox>
            <!--资源文件与Control显示之间通过Control的Uid属性关联-->
            <TextBlock x:Uid="tbWelcome" x:Name="msiTB" HorizontalAlignment="Left" Margin="20,0,0,0" 
                       TextWrapping="Wrap" FontSize="30" Foreground="Red"  VerticalAlignment="Top" Height="49" Width="287"/>
        </StackPanel>
    </Grid>
</Page>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void langComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string language = Convert.ToString(this.lanComboBox.SelectedValue);

            //方法1
            if (ApplicationLanguages.PrimaryLanguageOverride != language)
            {
                ApplicationLanguages.PrimaryLanguageOverride = language;

                ResourceManager.Current.DefaultContext.Reset();
                ResourceLoader loader = new ResourceLoader();
                this.msiTB.Text = loader.GetString("tbWelcome/Text");
            }

            //方法2
            if (ApplicationLanguages.PrimaryLanguageOverride != language)
            {
                ApplicationLanguages.PrimaryLanguageOverride = language;

                ResourceManager.Current.DefaultContext.Reset();
                this.msiTB.Text = ResourceManager.Current.MainResourceMap.GetValue("Resources/tbWelcome/Text").ValueAsString;
            }

        }
    }

posted on 2013-03-28 09:37  JackSlaterYu  阅读(210)  评论(0编辑  收藏  举报