C#:当我单击图像时,PointerPressed 已被调用两次 [英] C#: PointerPressed has been called twice when I click the image
问题描述
我是 UWP 的初学者.我想向更改 splitview
的打开状态的图像添加点击事件.所以我在 ma xaml 中有一个图像:
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"/>
我将 image_1_6_PointerPressed
定义如下:
private void image_1_6_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
mySplitView.IsPaneOpen = !mySplitView.IsPaneOpen;
}
但是当我点击图像时 mySplitView
打开和关闭!任何机构可以帮助我吗?谢谢.
But when I click on image the mySplitView
open and close! Can any body help me on this please? Thanks.
推荐答案
pointerpressed
不像点击事件那样工作.它在您按下并保持按钮以及您离开按钮事件完成时调用.因此,当您单击图像时,您会认为此事件调用了两次!您应该为此调用 Tapped
事件.
pointerpressed
doesn'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"/>
这篇关于C#:当我单击图像时,PointerPressed 已被调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!