Xamarin.forms 在特定平台上添加TapGestureRecognitor
是否可以仅在UWP上添加Xamarin.forms 在特定平台上添加TapGestureRecognitor,xamarin.forms,Xamarin.forms,是否可以仅在UWP上添加TapGestureRecognitor?像这样的 <OnPlatform x:TypeArguments="GestureRecognizers"> <OnPlatform.Platforms> <On Platform="UWP"> <TapGestureRecognizer Command="{Binding MyUWPCommand}"/> </O
TapGestureRecognitor
?像这样的
<OnPlatform x:TypeArguments="GestureRecognizers">
<OnPlatform.Platforms>
<On Platform="UWP">
<TapGestureRecognizer Command="{Binding MyUWPCommand}"/>
</On>
</OnPlatform.Platforms>
</OnPlatform>
为什么不在
MyUWPCommand
的代码中检查当前平台是否为UWP?如果是,则执行代码,如果不是,则不执行任何操作。在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>
只需将每个手势识别器包装到OnPlatform中即可
<ContentView.GestureRecognizers>
<OnPlatform x:TypeArguments="GestureRecognizer">
<OnPlatform.Platforms>
<On Platform="UWP">
<TapGestureRecognizer Command="{Binding MyUWPCommand}"/>
</On>
</OnPlatform.Platforms>
</OnPlatform>
</ContentView.GestureRecognizers>
您必须在Xaml中执行此操作吗?