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

标签 xaml xamarin xamarin.forms

我正在使用 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>

这不起作用,可能吗?

最佳答案

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

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

引用:Providing platform-specific values

关于xaml - 如何只为特定平台设置 OnPlatform?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60004581/

相关文章:

xamarin.ios - mach_vm_map 失败(错误代码=3)

xamarin - 使用隐藏在 Xamarin.Forms 中的 C# 代码访问控件

Xamarin 在 ScrollView 中形成 ListView 问题

ios - Xamarin形式FFImageLoading图像未显示

wpf - 如何解决 GridView SelectedItem 属性上的绑定(bind)路径错误?

c# - 绑定(bind)到自定义控件的一部分中的事件

c# - WPF TreeView HierarchicalDataTemplate - 绑定(bind)到具有多个子集合的对象

android - Xamarin Camera2Basic 示例在 UnlockFocus 调用后引发异常

ios - Xamarin:为 Visual Studio 2015 添加新项目时没有 iOS 类

c# - 如何设置 MahApps 窗口网格的样式?