温馨提示:本文翻译自stackoverflow.com,查看原文请点击:xaml - How to only set OnPlatform for a specific platform?
xamarin xamarin.forms xaml

xaml - 如何只为特定平台设置OnPlatform?

发布于 2020-04-04 00:39:32

我正在使用Xamarin.Forms进行编程。我想知道如何只OnPlatform在XAML中使用的单个平台设置高度请求吗?-1如果平台未被引用,我想保留默认值

我目前有以下代码:

<ListView.HeightRequest>
    <OnPlatform x:TypeArguments="x:Double">
        <On Platform="WPF" Value="153" />
        <On Platform="Android" Value="-1" />
        <On Platform="iOS" Value="-1" />
        <On Platform="UWP" Value="-1" />
    </OnPlatform>
</ListView.HeightRequest>

我希望我只需要写一些类似的东西:

<ListView.HeightRequest>
    <OnPlatform x:TypeArguments="x:Double">
        <On Platform="WPF" Value="153" />
    </OnPlatform>
</ListView.HeightRequest>

这行不通,可能吗?

查看更多

提问者
zhichaoxiang
被浏览
113
Jack Hua - MSFT 2020-02-05 09:59

您可以在一行中编写具有相同值的平台:

<ListView.HeightRequest>
    <OnPlatform x:TypeArguments="x:Double">
        <On Platform="WPF" Value="153" />
        <On Platform="Android,iOS,UWP" Value="-1" />
    </OnPlatform>
</ListView.HeightRequest>

参考:提供特定于平台的值