美好的一天,我有一个弹出用户控件,用户可以在其中与手势交互。我想要的是,当用户点击图像项时,会调用一个方法并关闭弹出窗口。但是我遇到的问题是,当点击用户控件中的图像项时,会触发用户控件中的所有点击事件方法。我尝试为每个设置不同的手势列表,但它似乎不起作用。这是我的代码:
myPopUp = new Popup();
myPopUp.Height = 400;
myPopUp.Width = 400;
//myPopUp.VerticalOffset = 100;
myPopUp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
myPopUp.VerticalAlignment = System.Windows.VerticalAlignment.Center;
layout_menu layouts = new layout_menu();
myPopUp.Child = layouts;
myPopUp.IsOpen = true;
GestureListener gesturelistener = GestureService.GetGestureListener(layouts);
gesturelistener.Tap += new EventHandler<GestureEventArgs>(onFirstImageTap);
GestureListener gesturelistener2 = GestureService.GetGestureListener(layouts);
gesturelistener2.Tap += new EventHandler<GestureEventArgs>(onSecondImageTap);
}
private void onFirstImageTap(object sender, GestureEventArgs e)
{
//LayoutPanel = 1;
MessageBox.Show("First image tapped");
myPopUp.IsOpen = false;
}
private void onSecondImageTap(object sender, GestureEventArgs e)
{
MessageBox.Show("Second image tapped");
myPopUp.IsOpen = false;
}
Layout_menu XAML:
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}" Margin="0,0,10,0">
<Grid x:Name="first_image_layout" HorizontalAlignment="Left" Height="150" Margin="13,10,0,0" VerticalAlignment="Top" Width="143">
<Image HorizontalAlignment="Left" Height="99" Margin="18,33,0,0" VerticalAlignment="Top" Width="107" Source="/Assets/Images/Navigation_Pane.png">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Tap="onFirstImageTap"></toolkit:GestureListener>
</toolkit:GestureService.GestureListener>
</Image>
</Grid>
<Grid x:Name="second_image_layout" HorizontalAlignment="Left" Height="156" Margin="13,161,0,0" VerticalAlignment="Top" Width="143">
<Image HorizontalAlignment="Left" Height="99" Margin="18,33,0,0" VerticalAlignment="Top" Width="107" Source="/Assets/Images/Navigation_Pane.png">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Tap="onSecondImageTap"></toolkit:GestureListener>
</toolkit:GestureService.GestureListener>
</Image>
</Grid>
当其中一个图像被点击时,如何关闭此弹出窗口?解决方案受到高度赞赏。提前致谢。