Pk19000 Pk19000 - 2 months ago 12
C# Question

C#: PointerPressed has been called twice when I click the image

I am beginner in UWP. I wanna add a click event to an image that change

splitview
's open-status. So I have an image in ma xaml:

<Image x:Name="image_1_6" HorizontalAlignment="Left" Height="200" Margin="1225,559,-171,0" VerticalAlignment="Top" Width="200" Source="Assets\images.jpg" PointerPressed="image_1_6_PointerPressed"/>


I define
image_1_6_PointerPressed
as like as this:

private void image_1_6_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
mySplitView.IsPaneOpen = !mySplitView.IsPaneOpen;
}


But when I click on image the
mySplitView
open and close! Can any body help me on this please? Thanks.

Answer

pointerpresseddoesn't working like as click event. It calls when you pressed and keep button and when you leave button event finishes. So when you click on image you think this event calls twice! You should call Tapped event for this.

<Image x:Name="image_1_6" HorizontalAlignment="Left" Height="200" Margin="1225,559,-171,0" VerticalAlignment="Top" Width="200" Source="Assets\images.jpg" Tapped="image_1_6_PointerPressed"/>