Xamarin.Forms 'non breaking space' 在本地化资源中

Xamarin.Forms 'non breaking space' in localisation resource

我想在我的资源中定义一个在呈现时不换行的文本。

如果我在 xaml(硬编码文本)中使用以下代码,它就可以工作。但是如果我将使用过的文本 Text="Premium Package" 移动到资源中,文本将被换行并且 & # 160 ; 将用作文本!

我该如何解决这个问题?

作品:

   <Label LineBreakMode="WordWrap" >
            <Label.FormattedText>
                    <FormattedString>
                        <Span Text="{x:Static resources:AppResources.PremiumView_Description01}"  Style="{StaticResource BlackSmall}" />
                        <Span Text=" " Style="{StaticResource BlackSmall}" />
                        <Span Text="Premium&#160;Package" Style="{StaticResource BlueSmall }" />
                        <Span Text=" " Style="{StaticResource BlackSmall}" />
                        <Span Text="{x:Static resources:AppResources.PremiumView_Description03}" Style="{StaticResource BlackSmall}" />
                    </FormattedString>
            </Label.FormattedText>
   </Label>

无效:

<Label LineBreakMode="WordWrap" >
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="{x:Static resources:AppResources.PremiumView_Description01}"  Style="{StaticResource BlackSmall}" />
                        <Span Text=" " Style="{StaticResource BlackSmall}" />
                        <Span Text="{x:Static resources:AppResources.PremiumView_Description02}" Style="{StaticResource BlueSmall }" />
                        <Span Text=" " Style="{StaticResource BlackSmall}" />
                        <Span Text="{x:Static resources:AppResources.PremiumView_Description03}" Style="{StaticResource BlackSmall}" />
                    </FormattedString>
                </Label.FormattedText>
            </Label>

如果您在 AppResources.resx 文件中添加 Premium&#160;Package&#160; 将不起作用,这是设计使然。

如果字符串在AppResources.resx文件中,用于Localization,则需要支持各种形式的不同字符。无论您在 AppResources.resx 文件中输入什么字符,它都会输出相同的字符。

如果要实现Space效果,在AppResources.resx文件中输入即可。

或单独添加"Premium&#160;Package"

AppResources.resx.

在 xaml 代码中,如以下代码。

 <Label LineBreakMode="WordWrap" TextType="Html" >
            <Label.FormattedText>
                <FormattedString>
                   
                   
                    <Span Text="{x:Static resources:AppResources.String1}"  />
                    <Span Text="&#160;"  />
                    <Span Text="{x:Static resources:AppResources.String2}"  />
                   
                </FormattedString>
            </Label.FormattedText>
        </Label>