Today I found an issue with the GestureRecognizer
and I'm not sure if this is a bug or just a layout problem.
I'm creating a card like layout for my app. It is pretty simple, it contains an Image
and 2 Labels
. To show the Image
and one Label
in one line I pack them into a StackLayout
with Horizontal Orientation. Then I create a new StackLayout
and add the layout and another label as Children.
public StackLayout CreateDashboardCard(string name, string icon, int itemsCount, double width = 250, double height = 150)
{
var nameLabel = new Label
{
Text = name,
FontSize = 20,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};
var iconToShow = new Image
{
Source = icon,
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Center
};
var itemsCountLabel = new Label
{
Text = _itemsCount.ToString(),
FontSize = 30,
HorizontalOptions = LayoutOptions.EndAndExpand,
VerticalOptions = LayoutOptions.Center
};
var upperLayout = new StackLayout
{
HeightRequest = height - 30,
Orientation = StackOrientation.Horizontal,
BackgroundColor = Color.Aqua,
Children =
{
iconToShow,
itemsCountLabel
}
};
var card = new StackLayout
{
Spacing = 10,
WidthRequest = width,
BackgroundColor = Color.Gray,
HeightRequest = height,
Orientation = StackOrientation.Vertical,
Children =
{
upperLayout,
nameLabel
}
};
return card;
}
So nothing really fancy or complex.
In the ContentPage I create a DashBoardCard and add an TapGestureRecognizer.
var testCard = _dashBoardCards.CreateDashboardCard("TestCard", "userlist.png", 5);
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (sender, e) =>
{
DisplayAlert("Test","test","Ok");
};
testCard.GestureRecognizers.Add(tapGestureRecognizer);
Now when I tap on the item only the nameLabel
responds to the tap event.
In my understanding the hole DashBoardCard is a rendered StackLayout
where I add the gesture recognizer to it or is that wrong?
Have someone experienced this too?