C#:单击图像时,PointerPressed已被调用两次

C#:单击图像时,PointerPressed已被调用两次,c#,win-universal-app,uwp,C#,Win Universal App,Uwp,我是UWP的初学者。我想向更改splitview打开状态的图像添加单击事件。因此,我有一个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_PointerP

我是UWP的初学者。我想向更改
splitview
打开状态的图像添加单击事件。因此,我有一个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"/>

但是当我点击图片时,mySplitView就会打开和关闭!有人能帮我吗?谢谢。

在诊断之前,您可以尝试以下方法:

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

您也可以尝试不同的事件

在诊断之前,您可以尝试以下操作:

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

您也可以尝试不同的事件

指针压缩的
与单击事件不一样。当您按下并保持按钮和离开按钮事件结束时,它会调用。所以,当你们点击图片时,你们会认为这个事件会重复两次! 您应该为此调用
Tapped
事件

<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"/>

指针压缩
的工作方式与单击事件不同。当您按下并保持按钮和离开按钮事件结束时,它会调用。所以,当你们点击图片时,你们会认为这个事件会重复两次! 您应该为此调用
Tapped
事件

<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"/>


如果所有其他方法都失败,您不妨尝试
如果(mySplitView.IsPaneOpen==false)mySplitView.IsPaneOpen=true;else mySplitView.IsPaneOpen=false
如果所有其他方法都失败了,您不妨尝试
如果(mySplitView.IsPaneOpen==false)mySplitView.IsPaneOpen=true;else mySplitView.IsPaneOpen=false我在代码隐藏方法image_1_6_pointer pressed中添加了一件事,adde.Handled=true;然后它不会调用超出需要的方法;然后它不会调用超出需要的方法。我尝试过这种方法,以防止在图像画布上使用笔输入时出现双重调用,但不起作用。我尝试过这种方法,以防止在图像画布上使用笔输入时出现双重调用,但不起作用。