Reputation: 45
<StackLayout Orientation="Horizontal" FlowDirection="RightToLeft" HorizontalOptions="EndAndExpand" Spacing="0">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="GoToBasket"></TapGestureRecognizer>
</StackLayout.GestureRecognizers>
<Frame x:Name="frmBasket" CornerRadius="24" Padding="8" BackgroundColor="#FFFFFF">
<StackLayout Orientation="Horizontal">
<Entry x:Name="lblTotalBasket" TextChanged="lblTotalBasket_TextChanged" HorizontalOptions="FillAndExpand" IsReadOnly="True" Text="{Binding TotalPrice, StringFormat='₺{0:0.00}'}" Margin="0, 0, 5, 0" HorizontalTextAlignment="Center" FontSize="13" VerticalTextAlignment="Center" FontAttributes="Bold" BackgroundColor="#FFFFFF" TextColor="{StaticResource Primary}"></Entry>
<Label x:Name="lblBasketIcon" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" BackgroundColor="Transparent" Text="" FontSize="15" TextColor="{StaticResource Primary}" Margin="8, 0, 0, 0" FontFamily="{StaticResource FontAwesomeSolid}"></Label>
</StackLayout>
</Frame>
</StackLayout>
StackLayout TapGestureRecognizer working except Entry element. I tried add TapGestureRecognizer and Focused attribute for Entry element but also not worked.
How StackLayout TapGestureRecognizer does work on Entry element tap ?
Upvotes: 1
Views: 1360
Reputation: 51
Try setting TapGesture for parent control and for your entry set InputTransparent="True" so that when you tap on entry it will actually recognized as tap on parent control.
Upvotes: 1
Reputation: 15816
If you set the IsReadOnly=false
to entry, the TapGestureRecognizer won't work because it will get fouced when tap it and user can type something. In this cause, you can call your method in the foucsed
event:
<Entry x:Name="lblTotalBasket" Focused="lblTotalBasket_Focused"/>
And in code behind:
private void lblTotalBasket_Focused(object sender, FocusEventArgs e)
{
Console.WriteLine("lblTotalBasket_Focused-entry");
}
If you set the IsReadOnly=ture
to entry, the TapGestureRecognizer will execute and you can also add TapGestureRecognizer to entry directly:
<Entry x:Name="lblTotalBasket" Focused="lblTotalBasket_Focused" HorizontalOptions="FillAndExpand" IsReadOnly="True" Text="{Binding TotalPrice, StringFormat='₺{0:0.00}'}" Margin="0, 0, 5, 0" HorizontalTextAlignment="Center" FontSize="13" VerticalTextAlignment="Center" FontAttributes="Bold" BackgroundColor="#FFFFFF">
<Entry.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"></TapGestureRecognizer>
</Entry.GestureRecognizers>
</Entry>
And in code behind:
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
Console.WriteLine("TapGestureRecognizer_Tapped-entry");
}
Update:
In Android, you also need to set isEnable = false
to make TapGestureRecognizer
work:
<Entry x:Name="lblTotalBasket" IsEnabled="False"/>
Upvotes: 3