Xamarin表示XAML OnPlatform VerticalOptions

Ahm*_*ker 1 c# xaml vertical-alignment xamarin

我想做的事情似乎很简单,但到目前为止,我一直在寻找大约一个小时没有运气.

我有以下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>
Run Code Online (Sandbox Code Playgroud)

但它给出了一个错误说:

Cannot assign property VerticalOptions, property does not exists, or is not assignable, or mismatching type between value and property
Run Code Online (Sandbox Code Playgroud)

我已经成功完成了相同的但是对于x类型的其他属性:布尔值,x:双倍和厚度...出于好奇,我一直在尝试找到一些文档,概述所有可用的x:TypeArguments作为参考但仍然没有运气也好.

gan*_*o55 6

你的问题就在这一行

<OnPlatform x:TypeArguments="x:String">
Run Code Online (Sandbox Code Playgroud)

你说的是值是一个字符串,但它是一个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>
Run Code Online (Sandbox Code Playgroud)

Xamarin文档,你可以看到VerticalOptionLayoutOption:

句法

public LayoutOptions VerticalOptions {get; 组; }

LayoutOptions,用于定义如何布置元素.除非另有说明,否则默认值为LayoutOptions.Fill.

我希望这可以帮到你.