繁体   English   中英

C#XAML-Windows 8.1应用程序多语言资源问题AppBar

[英]C# XAML - Windows 8.1 App Multilingual Resources Issue AppBar

我正在使用C#和XAML为Windows 8.1制作一个应用程序。 所有字符串都位于位于en-GB文件夹中的名为Resources.resw的资源文件中。

我正在使用XAML加载这样的字符串:

             <AppBarButton Icon="Document"
                           x:Uid="AddFiles" 
                           Label="Add files"  
                           Click="btnAddFiles_Click"/>

并像这样使用C#(用于MessageDialogs):

        var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
        var text = loader.GetString(@"Error") + exceptionRoutedEventArgs.ErrorMessage +                       
                    "\r\n\r\n" + loader.GetString(@"Error_FileTypeNotSupported")
        var messageDialog = new MessageDialog(text);
        messageDialog.ShowAsync();

其中exceptionRoutedEventArgs是ExceptionRoutedEventArgs对象。

当我运行我的应用程序时,一切正常。

开发我的应用程序的下一步是添加多语言支持。 我启用了多语言应用程序工具包,并添加了德语。 创建了文件夹MultilingualResources,并添加了用于德语翻译的.xlf文件。 我在PC上添加了德语作为主要语言,并且在运行应用程序时,显示了splashcreen并且代码正在运行,但是突然,当应该显示我的主页时,就会出现黑屏。 我试图再次运行它,以重建项目,但始终都存在相同的问题。 如果我删除了德语翻译文件(.xlf),问题就解决了,但是我需要翻译,所以我又添加了德语翻译文件,问题又再次出现了……实际上只是在我编写此线程时我意识到问题实际上是该应用程序的底部应用程序栏(背景为黑色)覆盖了整个屏幕(但应用程序栏上的所有控件都没有出现)。 令人惊讶的是,另一页的“顶部应用程序栏”工作正常。 我的底部应用程序栏没有什么特别的:只有一些网格,StackPanels和几个应用程序栏按钮,如第一个代码序列中所示。

这是顶级应用栏

  <Page.TopAppBar>
     <CommandBar>

        <CommandBar.SecondaryCommands>

            <AppBarButton Label="Start" Icon="Play" Click="StartButton_OnClick"/>
            <AppBarButton Label="Stop" Icon="Stop" Click="StopButton_OnClick"/>

        </CommandBar.SecondaryCommands>

     </CommandBar>
 </Page.TopAppBar>

这是底部的应用栏

<Page.BottomAppBar>
    <AppBar IsSticky="True"     
            Width="{Binding Path=MainPageSize.Width}"
            Height="{Binding Path=MainPageSize.Height, Converter={StaticResource  MultiplierConverter}, ConverterParameter='0.15'}" IsOpen="True">

        <userControls:MainPageBottomAppBar/>

    </AppBar>
</Page.BottomAppBar>

变量MainPageSize具有页面的尺寸,并且BottomAppBar的Width假定与页面的Width相等,而Height的高度等于页面的15%。 如果未激活语言资源,这将非常有效。 问题显然是Converter不起作用,并使Bar的高度等于Page之一,并且内容被隐藏了(AppBarButtons)。 如果我使用Height =“ 200”,则AppBar不再占据整个页面,但是内容仍然被隐藏。

 public class MultiplierConverter : IValueConverter
   {
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        var a = System.Convert.ToDouble(value);
        var b = System.Convert.ToDouble(parameter);

        return a*b;
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}

那么有人可以告诉我如何解决这个问题吗?

LE:好的,我发现了问题。 实际上,这有点好笑。 英文的十进制数字使用“。”,因此使用英文时0.15将被解释为0.15,而使用德语时则将0.15解释为15,因为它们使用“,”代表小数。 问题是我仍然不知道要解决这个问题。 是像文化相关的东西解析双数吗?

好,所以我要做的就是更换

        var b = System.Convert.ToDouble(parameter);

        var b = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture);

无论如何,谢谢您的帮助! :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM