我正在尝试使用下面的这个标记使用StackLayout和RelativeLayout构建一个简单的Xamarin.Forms页面,尝试在左侧完成一个标签,镜像右侧80%宽度的滑块值。这是整个页面的标记:
<?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="XamarinAds.OptionsPage" Title="Options">
<ContentPage.Content>
<StackLayout Padding="10">
<Label Text="Rooms:" VerticalOptions="CenterAndExpand" />
<RelativeLayout>
<Slider x:Name="roomsSlider" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.80}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.10}" />
<Label BindingContext="{x:Reference Name=roomsSlider}" Text="{Binding Value, StringFormat='{0:F0}'}" />
</RelativeLayout>
<Label Text="Maximum price (M SEK):" VerticalOptions="CenterAndExpand" />
<RelativeLayout>
<Slider x:Name="priceSlider" Value="1" Minimum="0" Maximum="10" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.80}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.10}" />
<Label BindingContext="{x:Reference Name=priceSlider}" Text="{Binding Value, StringFormat='{0:F0}'}" />
</RelativeLayout>
<Button Text="Filter" />
<Button Text="Default values" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
这应该是有效的标记,并且它在Android模拟器中也可以毫无问题地执行。但是,当试图在实际的Android设备(HTC One with Android 4.4)上运行时,我会遇到异常。原来是导致错误的RelativeLayout.WidthConstraint和RelativeLayout.XConstraint。
使用此标记时:
<?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="XamarinAds.OptionsPage" Title="Options">
<ContentPage.Content>
<StackLayout Padding="10">
<RelativeLayout>
<Slider x:Name="roomsSlider" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.80}" />
</RelativeLayout>
</StackLayout>
</ContentPage.Content>
</ContentPage>
我得到以下例外情况:
[MonoDroid] UNHANDLED EXCEPTION: System.FormatException: Unknown char
[MonoDroid] at double.Parse (string,System.Globalization.NumberStyles,System.IFormatProvider) <0x00078>
[MonoDroid] at double.Parse (string) <0x0001b>
[MonoDroid] at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (object,System.Type,System.Func`1<System.Reflection.MemberInfo>) <0x00123>
[MonoDroid] at Xamarin.Forms.Xaml.MarkupExtensionParser.SetPropertyValue (string,string,object) <0x000e7>
[MonoDroid] at Xamarin.Forms.Xaml.MarkupExpressionParser.HandleProperty (string,System.IServiceProvider,string&) <0x00183>
[MonoDroid] at Xamarin.Forms.Xaml.MarkupExtensionParser.Parse (string,string&,System.IServiceProvider) <0x002f7>
[MonoDroid] at Xamarin.Forms.Xaml.MarkupExpressionParser.ParseExpression (string&,System.IServiceProvider) <0x001cf>
[MonoDroid] at Xamarin.Forms.Xaml.MarkupNode.ApplyTo (object,Xamarin.Forms.Xaml.XmlName,Xamarin.Forms.INameScope) <0x0021f>
[MonoDroid] at Xamarin.Forms.Xaml.INodeExtension.ApplyProperties (Xamarin.Forms.Xaml.IElementNode,object,Xamarin.Forms.INameScope) <0x001d3>
[MonoDroid] at Xamarin.Forms.Xaml.ElementNode.ApplyProperties (Xamarin.Forms.INameScope) <0x0001f>
[MonoDroid] at Xamarin.Forms.Xaml.ElementNode.Create (Xamarin.Forms.IElement,Xamarin.Forms.INameScope) <0x0040f>
[MonoDroid] at Xamarin.Forms.Xaml.ElementNode.ApplyTo (object,Xamarin.Forms.Xaml.XmlName,Xamarin.Forms.INameScope) <0x00247>
[MonoDroid] at Xamarin.Forms.Xaml.INodeExtension.ApplyProperties (Xamarin.Forms.Xaml.IElementNode,object,Xamarin.Forms.INameScope) <0x001d3>
[MonoDroid] at Xamarin.Forms.Xaml.ElementNode.ApplyProperties (Xamarin.Forms.INameScope) <0x0001f>
[MonoDroid] at Xamarin.Forms.Xaml.ElementNode.Create (Xamarin.Forms.IElement,Xamarin.Forms.INameScope) <0x0040f>
[MonoDroid] at Xamarin.Forms.Xaml.ListNode.ApplyTo (object,Xamarin.Forms.Xaml.XmlName,Xamarin.Forms.INameScope) <0x0069b>
[MonoDroid] at Xamarin.Forms.Xaml.INodeExtension.ApplyProperties (Xamarin.Forms.Xaml.IElementNode,object,Xamarin.Forms.INameScope) <0x001d3>
[MonoDroid] at Xamarin.Forms.Xaml.ElementNode.ApplyProperties (Xamarin.Forms.INameScope) <0x0001f>
[MonoDroid] at Xamarin.Forms.Xaml.ElementNode.Create (Xamarin.Forms.IElement,Xamarin.Forms.INameScope) <0x0040f>
[MonoDroid] at Xamarin.Forms.Xaml.ElementNode.ApplyTo (object,Xamarin.Forms.Xaml.XmlName,Xamarin.Forms.INameScope) <0x00247>
[MonoDroid] at Xamarin.Forms.Xaml.INodeExtension.ApplyProperties (Xamarin.Forms.Xaml.IElementNode,object,Xamarin.Forms.INameScope) <0x001d3>
[MonoDroid] at Xamarin.Forms.Xaml.RootNode.ApplyProperties (Xamarin.Forms.INameScope) <0x0005f>
[MonoDroid] at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.VisualElement,string) <0x000e7>
[MonoDroid] at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.VisualElement,System.Type) <0x00053>
[MonoDroid] at Xamarin.Forms.Xaml.Extensions.LoadFromXaml<XamarinAds.OptionsPage> (XamarinAds.OptionsPage,System.Type) <0x0001f>
[MonoDroid] at XamarinAds.OptionsPage.InitializeComponent () <0x00023>
[MonoDroid] at XamarinAds.OptionsPage..ctor () <0x0001b>
[MonoDroid] at XamarinAds.StartPage.OnOptionsButtonClicked (object,System.EventArgs) <0x00033>
[MonoDroid] at Xamarin.Forms.Button.SendClicked () <0x0006b>
[MonoDroid] at Xamarin.Forms.Platform.Android.ButtonRenderer/ButtonClickListener.OnClick (Android.Views.View) <0x000a7>
[MonoDroid] at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) <0x0005f>
[MonoDroid] at (wrapper dynamic-method) object.0bd85240-ae6f-4264-9b6b-1f5e51891117 (intptr,intptr,intptr) <0x00043>
[mono]
[mono] Unhandled Exception:
[mono] System.FormatException: Unknown char
[mono] at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in <filename unknown>:0
[mono] at System.Double.Parse (System.String s) [0x00000] in <filename unknown>:0
[mono] at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1 minfoRetriever) [0x00000] in <filename unknown>:0
[mono] at Xamarin.Forms.Xaml.MarkupExtensionParser.SetPropertyValue (System.String prop, System.String strValue, System.Object value) [0x00000] in <filename unknown>:0
[mono] at Xamarin.Forms.Xaml.MarkupExpressionParser.HandleProperty (System.String prop, IServiceProvider serviceProvider, System.String& remaining) [0x00000] in <filename unknown>:0
[mono] at Xamarin.Forms.Xaml.MarkupExtensionParser.Parse (System.String match, System.String& expression, IServiceProvider serviceProvider) [0x00000] in <filename unknown>:0
[mono] at Xamarin.Forms.Xaml.MarkupExpressionParser.ParseExpression (System.String& expre
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Unknown char
[mono-rt] at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in <filename unknown>:0
[mono-rt] at System.Double.Parse (System.String s) [0x00000] in <filename unknown>:0
[mono-rt] at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1 minfoRetriever) [0x00000] in <filename unknown>:0
[mono-rt] at Xamarin.Forms.Xaml.MarkupExtensionParser.SetPropertyValue (System.String prop, System.String strValue, System.Object value) [0x00000] in <filename unknown>:0
[mono-rt] at Xamarin.Forms.Xaml.MarkupExpressionParser.HandleProperty (System.String prop, IServiceProvider serviceProvider, System.String& remaining) [0x00000] in <filename unknown>:0
[mono-rt] at Xamarin.Forms.Xaml.MarkupExtensionParser.Parse (System.String match, System.String& expression, IServiceProvider serviceProvider) [0x00000] in <filename unknown>:0
[mono-rt] at Xamarin.Forms.Xaml.MarkupExpressionParser.ParseExpression (System.
我做错了什么或者我抓到了一个错误?有没有其他简单的方法来完成我的页面设计?