简体   繁体   中英

Xamarin.Forms 'non breaking space' in localisation resource

I would like to have a text defined in my resources which is not wrapped when rendered.

If I use the following code in xaml (hardcoded text) it works. But if I move the used text Text="Premium Package" to the resources, the text will be wrapped and the & # 160; will be used as a text!

How can I solve this?

Works:

   <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>

Does not work:

<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>

If you add Premium&#160;Package in the AppResources.resx file, &#160; will not worked, it is by design.

If string in AppResources.resx file, it used for Localization , it will need to support diferent characters of various forms. whatever characters that you input the AppResources.resx file, it will output the same characters.

If you want to use achieve the Space effect, just input it in the AppResources.resx file.

在此处输入图像描述

Or add this "Premium&#160;Package" separately.

In the AppResources.resx .

在此处输入图像描述

In the xaml code like following code.

 <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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