问题
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.
回答1:
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"/>
回答2:
Until you diagnose, you can try something like:
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;
}
}
You can also try a different event
来源:https://stackoverflow.com/questions/39463158/c-pointerpressed-has-been-called-twice-when-i-click-the-image