Drake
Drake

Reputation: 2703

Add TapGestureRecognizer on platform specific

Is it possible to add a TapGestureRecognizer on only UWP? Something like this

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

Upvotes: 1

Views: 1047

Answers (3)

Paul Aicher
Paul Aicher

Reputation: 261

Just have to wrap each GestureRecognizer in an OnPlatform

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

Upvotes: 0

Ben
Ben

Reputation: 2985

In 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>

Upvotes: 3

Gerald Versluis
Gerald Versluis

Reputation: 34013

Why not just in the code of the MyUWPCommand check if the current platform is UWP? If so, execute the code, if not, do nothing.

Upvotes: 1

Related Questions