首页 > 解决方案 > 在特定平台上添加 TapGestureRecognizer

问题描述

TapGestureRecognizer是否可以仅在 UWP 上添加一个?像这样的东西

<OnPlatform x:TypeArguments="GestureRecognizers">
    <OnPlatform.Platforms>
        <On Platform="UWP">
            <TapGestureRecognizer Command="{Binding MyUWPCommand}"/>
        </On>
    </OnPlatform.Platforms>
</OnPlatform>

标签: xamarin.forms

解决方案


在 XAML 中:

<OnPlatform x:TypeArguments="Label">
    <On Platform="UWP">
        <Label Text="TapGestureRecognizer for UWP">
            <Label.GestureRecognizers>
                <TapGestureRecognizer Command="{Binding MyUWPCommand}" />
            </Label.GestureRecognizers>
        </Label>
    </On>
    <On Platform="Android, iOS">
        <Label Text="No GestureRecognizers for Android, iOS" />
    </On>
</OnPlatform>

推荐阅读