Search code examples
c#.netmaui

C# MAUI Event GraphicsView StartInteraction not working


If i tap on GraphicsView should event and call method tap, but debugger does not respond on tap. Label do not change too.

XAML:

<Label 
    x:Name="lb"
    Text="You touch nothing"/>

<GraphicsView
    x:Name="tralala"
    StartInteraction="tap"/>

CS:

private void tap(object sender, TouchEventArgs e)
{
    lb.Text = "You touch my tralala"
}

I try add GestureRecognizers :

<GraphicsView
    x:Name="previewer"
    StartInteraction="tap">

    <GraphicsView.GestureRecognizers >

        <TapGestureRecognizer Tapped="tapp"/>
        
    </GraphicsView.GestureRecognizers>
    
</GraphicsView>

CS:

private void tapp(object sender, TappedEventArgs e)
{
    lb.Text = "You touch my tralala"
}

but this not helping


Solution

  • If i tap on GraphicsView should event and call method tap, but debugger does not respond on tap

    The GraphicsView's default HeightRequest and WidthRequest is -1 on android, so you need to set the value of them to make the GraphicsView can render on the screen.

    You can get the distance by : var dis = firstpoint.Distance(secondpoint). Just check the source code: public double Distance.

    And for more information about the api, you can check the official document about Microsoft.Maui.Graphics.Point.