【发布时间】:2018-09-08 12:28:54
【问题描述】:
我们正在 Visual Studio 中使用 xamarin 表单构建一个跨平台应用程序,对于 iOS,该应用程序运行良好,但是当我构建它并在我的手机甚至模拟器上运行时,空格或只是空格是从我的字符串中删除,使用静态资源或只是 xaml 文件中的字符串本身,编码是 utf-8 并且我确实检查了 strings.resx 都是 xml:space="preserve"
我已经检查了我能想到的一切,如果有人能在这方面启发我
例如隐私政策字符串中的空格,当在 android 上运行时,它会删除空格...即使将字符串放在资源或 xaml 页面上也没关系
谢谢
编辑:遵循部分代码
xaml 页面前
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Driver.View.Register"
xmlns:resx="clr-namespace:Driver.Infra.Resources;assembly=Driver"
xmlns:viewt="clr-namespace:Driver.ViewTemplate;assembly=Driver"
Title="Faça seu Cadastro">
<ContentPage.Content>
<RelativeLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<StackLayout
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=0}"
Orientation="Vertical"
VerticalOptions="FillAndExpand"
Padding="15">
<ScrollView>
<StackLayout Orientation="Vertical">
<!--<Image Source="logotipo.png"/>-->
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" Margin="0,20,0,0">
<RelativeLayout VerticalOptions="FillAndExpand" HorizontalOptions="Start" WidthRequest="80">
<viewt:CustomPicker
x:Name="PckDDI"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=0}"
Title="{x:Static resx:Strings.CountryCode}"
HeightRequest="40"
HorizontalOptions="FillAndExpand"/>
<Label RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=PckDDI, Property=Width, Factor=1, Constant=0}"
Text="{x:Static viewt:FontAwesome.faBars}"
TextColor="{x:StaticResource ColorPrimary}"
FontSize="Small"
FontFamily="FontAwesome"
HorizontalOptions="End"
Margin="0,12,10,0"
InputTransparent="True"/>
</RelativeLayout>
<viewt:CustomEntry
MaxLength="11"
Keyboard="Numeric"
Placeholder="{x:Static resx:Strings.PhoneEx}"
PlaceholderColor="LightGray"
HeightRequest="40"
HorizontalOptions="FillAndExpand"
x:Name="TxtPhone"/>
</StackLayout>
<viewt:CustomEntry
MaxLength="50"
Keyboard="Default"
Placeholder="{x:Static resx:Strings.Name}"
PlaceholderColor="LightGray"
HeightRequest="40"
HorizontalOptions="FillAndExpand"
x:Name="TxtName"/>
<viewt:CustomEntry
MaxLength="8"
Keyboard="Default"
Placeholder="{x:Static resx:Strings.Plate}"
PlaceholderColor="LightGray"
HeightRequest="40"
HorizontalOptions="FillAndExpand"
x:Name="TxtPlate"/>
<RelativeLayout VerticalOptions="FillAndExpand">
<viewt:CustomPicker
x:Name="PckVehicleType"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=0}"
Title="{x:Static resx:Strings.VehicleType}"
HeightRequest="40"
HorizontalOptions="FillAndExpand"/>
<Label RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=PckVehicleType, Property=Width, Factor=1, Constant=0}"
Text="{x:Static viewt:FontAwesome.faBars}"
TextColor="{x:StaticResource ColorPrimary}"
FontSize="Small"
FontFamily="FontAwesome"
HorizontalOptions="End"
Margin="0,12,10,0"
InputTransparent="True"/>
</RelativeLayout>
<RelativeLayout VerticalOptions="FillAndExpand">
<viewt:CustomPicker
x:Name="PckBodyType"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=0}"
Title="{x:Static resx:Strings.TransportType}"
HeightRequest="40"
HorizontalOptions="FillAndExpand"/>
<Label RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=PckBodyType, Property=Width, Factor=1, Constant=0}"
Text="{x:Static viewt:FontAwesome.faBars}"
TextColor="{x:StaticResource ColorPrimary}"
FontSize="Small"
FontFamily="FontAwesome"
HorizontalOptions="End"
Margin="0,12,10,0"
InputTransparent="True"/>
</RelativeLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" Margin="0,20,0,0">
<Switch
x:Name="SwtPrivacyPolicy"
HorizontalOptions="Start"
IsToggled="True"/>
<Label
Text="{x:Static resx:Strings.PrivacyPolicyText}"
TextColor="Black"
FontSize="Micro">
<Label.GestureRecognizers>
<TapGestureRecognizer
Tapped="LabelPrivacyPolicy_Tapped"
NumberOfTapsRequired="1"/>
</Label.GestureRecognizers>
</Label>
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Switch
x:Name="SwtReceivePrepaidCard"
HorizontalOptions="Start"
IsToggled="False"/>
<Label
Text="{x:Static resx:Strings.PrePaidCardText}"
TextColor="Black"
FontSize="Micro">
<Label.GestureRecognizers>
<TapGestureRecognizer
Tapped="LabelReceivePrepaidCard_Tapped"
NumberOfTapsRequired="1"/>
</Label.GestureRecognizers>
</Label>
</StackLayout>
</StackLayout>
</ScrollView>
<StackLayout Orientation="Vertical" Margin="0,20,0,0">
<viewt:CustomButton
x:Name="ButtonRegister"
Text="{x:Static resx:Strings.Register}"
TextColor="White"/>
</StackLayout>
</StackLayout>
<viewt:LoadingView
x:Name="LoadingIndicator"
IsVisible="false"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=0}"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"/>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
资源字符串示例
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="PrivacyPolicyText" xml:space="preserve">
<value>Read and Accept the TERMS AND CONDITIONS about the use of the plataform and privacy policy</value>
</data>
【问题讨论】:
-
这个太含糊了,可能贴一下对应的组件,e.g.资源代码、xaml 页面等
-
@Csharpest 我的错,添加了一些代码
-
只是一些想法:问题是否仅出现在 FontSize="Micro" 上?也许您在 Android 上为您的标签自定义渲染器会导致问题?
-
@user2074945 不,即使使用默认的“欢迎使用 xamarin 表单”内容页面,它仍然会删除空格
标签: c# android xamarin.forms cross-platform