Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have multiple spans within a label. Some spans have a tapped event, and some don't. If two spans with a tapped event wrap to the same line, tapping on the last span will trigger both of the tapped events. If the two spans don't wrap and are on separate lines, it works fine.

<Label VerticalOptions="Start" 
                HorizontalTextAlignment="Center"
                FontSize="Micro"
                Margin="70,0,70,0"
                LineBreakMode="CharacterWrap">
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="This text cannot be tapped. " ></Span>
                        <Span Text="This text can " TextDecorations="Underline">
                            <Span.GestureRecognizers>
                                <TapGestureRecognizer Tapped="OnTextOneTapped"/>
                            </Span.GestureRecognizers>
                        </Span>
                        <Span Text="and "></Span>
                        <Span Text="this text can also be tapped" TextDecorations="Underline">
                            <Span.GestureRecognizers>
                                <TapGestureRecognizer Tapped="OnTextTwoTapped"/>
                            </Span.GestureRecognizers>
                        </Span>
                        <Span Text="."></Span>
                    </FormattedString>
                </Label.FormattedText>
            </Label>
private void OnTextOneTapped(object sender, EventArgs e)
        {
            DisplayAlert("Tap Alert", "You Tapped Text One", "OK");
        }

If the screen displays the tapped events text on different lines, it works fine:

This text cannot be tapped. This text can
and this text can also be tapped.

If any wrapping occurs where part of the tapped event shares a line with another tapped event, clicking on the latter of the two will cause both tapped events to fire:

This text cannot be tapped. This text
can and this text can also be tapped.

Tapping on the text "this text can also be tapped" will fire both OnTextOneTapped and OnTextTwoTapped. Tapping on the text "This text can" will only fire OnTextOneTapped.

Are my tapped event spans too close together (only separated by the word "and")? I only want one tapped event to fire per tap.


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

1 Answer

I have solution other for you:

  • Solution: You make a stacklayout contains multiple label, and excute tapped event.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...