Xamarin 表格 XAML OnPlatform VerticalOptions
Xamarin Forms XAML OnPlatform VerticalOptions
我想做的事情可能看起来很简单,但我一直在寻找大约一个小时,但到目前为止没有运气。
我有以下XAML
<StackLayout Grid.Row="2" Margin="20,20,20,20">
<StackLayout.VerticalOptions>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="CenterAndExpand" />
<On Platform="iOS" Value="EndAndExpand" />
</OnPlatform>
</StackLayout.VerticalOptions>
</StackLayout>
但它给出了一个错误提示:
Cannot assign property VerticalOptions, property does not exists, or is not assignable, or mismatching type between value and property
我已经成功地完成了同样的工作,但是对于 x:Boolean、x:Double 和厚度类型的其他属性...出于好奇,我也一直在尝试找到一些概述所有这些属性的文档可用 x:TypeArguments 作为参考,但仍然没有运气。
你的问题出在这一行
<OnPlatform x:TypeArguments="x:String">
你是说该值是一个字符串,但它是 LayoutOptions
类型。所以改变这个,它有效:
<StackLayout Margin="20,20,20,20">
<StackLayout.VerticalOptions>
<OnPlatform x:TypeArguments="LayoutOptions">
<On Platform="Android" Value="CenterAndExpand" />
<On Platform="iOS" Value="EndAndExpand" />
</OnPlatform>
</StackLayout.VerticalOptions>
</StackLayout>
在Xamarin documentation中你可以看到VerticalOption
是一个LayoutOption
:
Syntax
public LayoutOptions VerticalOptions { get; set; }
Value
A LayoutOptions which defines how to lay out the element. Default value is LayoutOptions.Fill unless otherwise documented.
希望对您有所帮助。
我想做的事情可能看起来很简单,但我一直在寻找大约一个小时,但到目前为止没有运气。
我有以下XAML
<StackLayout Grid.Row="2" Margin="20,20,20,20">
<StackLayout.VerticalOptions>
<OnPlatform x:TypeArguments="x:String">
<On Platform="Android" Value="CenterAndExpand" />
<On Platform="iOS" Value="EndAndExpand" />
</OnPlatform>
</StackLayout.VerticalOptions>
</StackLayout>
但它给出了一个错误提示:
Cannot assign property VerticalOptions, property does not exists, or is not assignable, or mismatching type between value and property
我已经成功地完成了同样的工作,但是对于 x:Boolean、x:Double 和厚度类型的其他属性...出于好奇,我也一直在尝试找到一些概述所有这些属性的文档可用 x:TypeArguments 作为参考,但仍然没有运气。
你的问题出在这一行
<OnPlatform x:TypeArguments="x:String">
你是说该值是一个字符串,但它是 LayoutOptions
类型。所以改变这个,它有效:
<StackLayout Margin="20,20,20,20">
<StackLayout.VerticalOptions>
<OnPlatform x:TypeArguments="LayoutOptions">
<On Platform="Android" Value="CenterAndExpand" />
<On Platform="iOS" Value="EndAndExpand" />
</OnPlatform>
</StackLayout.VerticalOptions>
</StackLayout>
在Xamarin documentation中你可以看到VerticalOption
是一个LayoutOption
:
Syntax
public LayoutOptions VerticalOptions { get; set; }
Value
A LayoutOptions which defines how to lay out the element. Default value is LayoutOptions.Fill unless otherwise documented.
希望对您有所帮助。