简体   繁体   中英

Closing a Popup on a UserControl on 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.

You will need to use the key up or key down event of your user control and detect the key like this:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM