在BackKeyPress上关闭UserControl上的Popup(Closing a Popup on a UserControl on BackKeyPress)

我在windows phone 8.1 silverlight中有一个项目,其中我有一个用户控件,它显示在主页面按钮上的点击事件中。 并且该用户控件有一个按钮。 点击该按钮后会出现一个弹出窗口,这个弹出窗口也是一个UserControl。 现在我想在BackKeypress上关闭这个Popup。 由于UserControl无法拥有BackkeyPress事件,因此难以实现。 那是可能的,如果是的话怎么样?

请告诉我..

提前感谢您的帮助。

I have a project in windows phone 8.1 silverlight in which I have a User Control which is displayed on a click event on a button from the main page. And that user control has a button. upon clicking that button a popup appears this popup is also a UserControl. Now I want to close this Popup on BackKeypress. As UserControl cannot have the BackkeyPress event, its difficult to that. So is it possible and if yes how?

Please let me know..

Thanks for help in advance.

最满意答案

您需要使用用户控件的按键启动或按键事件,并检测如下所示的键:

private void usercontrol1_KeyUp(object sender, KeyEventArgs e) { If (e.KeyCode == Keys.Back) { //do something } }

I got it and its working like this I added this code in MainPage.xaml.cs in OnBackkeyPress()

if(usercontrol1.Visibility==Visibility.Visible && usercontrol.popup_usercontrol2.IsOpen) { UC_UserProfile.pop_upAddVehicles.IsOpen = false; e.cancel=true; }

where usercontrol1 is the control coming on click of button on mainpage and popup_usercontrol2 is the popup coming on click of buttom on usercontrol1.

更多推荐