1

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

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

3 回答 3

2

在 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>
于 2018-06-05T20:46:44.080 回答
1

为什么不在MyUWPCommand检查当前平台是否为 UWP 的代码中?如果是,则执行代码,如果不是,则不执行任何操作。

于 2018-05-31T05:56:02.780 回答
0

只需将每个 GestureRecognizer 包装在 OnPlatform 中

<ContentView.GestureRecognizers>
  <OnPlatform x:TypeArguments="GestureRecognizer">
    <OnPlatform.Platforms>
        <On Platform="UWP">
            <TapGestureRecognizer Command="{Binding MyUWPCommand}"/>
        </On>
    </OnPlatform.Platforms>
  </OnPlatform>
</ContentView.GestureRecognizers>
于 2021-04-26T23:03:39.110 回答