Reputation: 289
I have been facing an issue many have been in the past but none of the solutions seem to work.
I have a Grid with in it a StackLayout with TapGesture.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:local="clr-namespace:WodTracker.App.Components"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WodTracker.App.Pages.Account.PinCodePage"
BackgroundColor="White">
<ContentPage.Content>
<StackLayout VerticalOptions="FillAndExpand" BackgroundColor="White">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="NumberCommand" CommandParameter="1"/>
</StackLayout.GestureRecognizers>
<Label HorizontalOptions="Center" VerticalOptions="EndAndExpand" Text="1" FontSize="Title" FontAttributes="Bold" TextColor="Black"></Label>
<Label HorizontalOptions="Center" VerticalOptions="EndAndExpand" Text=" " FontSize="Small" TextColor="Black"></Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
The code that should be hit is as followed. No initializing in the constructor just method.
private async void NumberCommand(object sender, EventArgs e)
{
var button = sender;
}
On Android the Tapped Command "NumberCommand" is executed. But on iOS it does not fire. On this website I have found people mentioning
InputTransparent="True"
I have tried adding this to the Parent Grid and the StackLayout without any success.
Hope someone can help.
I am using Visual Studio 2022 and Xamarin Forms 5.0.0.2244
Solved
It was an issue with 'InputTransparent="True"', after rebuilding the page step by step based on comments from ToolmakerSteve I was able to fix it. Thanks for all the help.
Upvotes: 3
Views: 1218
Reputation: 289
It was an issue with 'InputTransparent="True"', after rebuilding the page step by step based on comments from ToolmakerSteve I was able to fix it. Thanks for all the help.
Code
<StackLayout VerticalOptions="FillAndExpand" BackgroundColor="White">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="NumberCommand" CommandParameter="1"/>
</StackLayout.GestureRecognizers>
<Label HorizontalOptions="Center" VerticalOptions="EndAndExpand" Text="1" FontSize="Title" FontAttributes="Bold" TextColor="Black"></Label>
<Label HorizontalOptions="Center" VerticalOptions="EndAndExpand" Text=" " FontSize="Small" TextColor="Black"></Label>
</StackLayout>
Code behind
private async void NumberCommand(object sender, EventArgs e)
{
var button1 = (TapGestureRecognizer)sender;
string commandParameter = button1.CommandParameter.ToString();
}
Upvotes: 1