Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

xaml - TapGesture won't fire when adjusted inside a layout Xamarin

So basically I have an annoying thing when I'm trying to adjust my frame inside an AbsoluteLayout such:

<AbsoluteLayout Grid.Column="4">
<Frame CornerRadius="20" 
    Padding="0"  
    BorderColor="#9f6b34"  
    Background="Transparent">
    <Frame.GestureRecognizers>
         <TapGestureRecognizer Tapped="fourthButton_Clicked"/>
    </Frame.GestureRecognizers>
         <Label Text="Classic and traditional" 
                Padding="35" 
                FontSize="40"
                FontFamily="font2" 
                HorizontalTextAlignment="Center"
                TextColor="#211717">
          </Label>
     </Frame>

When the code is like this it's fine but when I try to adjust the frames' position with .LayoutBounds it just won't click. I've tried changing it to a StackLayout and click event fires sometimes in various different positions inside the frame. I've put ImageButton, regular button and also tried using my label's GestureRecognizer but it just won't click when I made adjustments. here is a gif of the situtation. the top frame isn't adjusted the bottom one is


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When the code is like this it's fine but when I try to adjust the frames' position with .LayoutBounds it just won't click.

I try your code, and it works fine, having no problem, please take a look the following code:

<StackLayout>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />

            </Grid.RowDefinitions>
            <AbsoluteLayout>
                <Frame
                    Padding="0"
                    AbsoluteLayout.LayoutBounds="0, 10, 300, 200"
                    BorderColor="#9f6b34"
                    CornerRadius="20">
                    <Frame.GestureRecognizers>
                        <TapGestureRecognizer Tapped="fourthButton_Clicked" />
                    </Frame.GestureRecognizers>
                    <Label
                        Padding="35"
                        FontFamily="font2"
                        FontSize="40"
                        HorizontalTextAlignment="Center"
                        Text="Classic and traditional"
                        TextColor="#211717" />
                </Frame>
            </AbsoluteLayout>

            <StackLayout Grid.Row="1">
                <Frame
                    Padding="0"
                    BorderColor="#9f6b34"
                    CornerRadius="20">
                    <Frame.GestureRecognizers>
                        <TapGestureRecognizer Tapped="fourthButton_Clicked" />
                    </Frame.GestureRecognizers>
                    <Label
                        Padding="35"
                        FontFamily="font2"
                        FontSize="40"
                        HorizontalTextAlignment="Center"
                        Text="Classic and traditional"
                        TextColor="#211717" />
                </Frame>
            </StackLayout>
        </Grid>
    </StackLayout>

I put Frame in AbsoluteLayout and also use AbsoluteLayout.LayoutBounds to adjust Frame poaition, I also put frame in StackLayout, it also works fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.5k users

...