0
votes

I am developing a Windows Phone app and need to implement below functionality:-

There is logged in section in the app. And if user is idle for 5 mins MessageBox should come saying "Session Time Out. Please login again." with OK button on Message Box and on click of OK button user will be logged out of application and login page should come.

This is implemented successfully but if the user clicks Hardware Back button of Windows Phone, MessageBox disappears and user can still access the app even after 5 minutes.

Please let me know how to restrict Hardware Back when MessageBox is in open state and Message box should remain active till the time user clicks Ok button.

Thanks in advance.

Regards, Jatin Juneja

3
How about making your application to log out user upon Message Box closed, no matter how it closed (pressing OK button, or hardware back button).har07

3 Answers

0
votes

Just override make this event on your page cs.

 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
            {
                base.OnBackKeyPress(e);
                e.Cancel = true;
            }

e.Cancel=true; suppresses the back key press.

0
votes

I would follow har07 comment and use MessageBoxReasult, it can look in a very simple example like this:

MessageBoxResult result = MessageBox.Show("Session Time Out. Log in again?", "Question", MessageBoxButton.OKCancel);
// code after user click
if (result == MessageBoxResult.OK) NavigationService.Navigate(new Uri("/LoginPage.xaml", UriKind.RelativeOrAbsolute));
else NavigationService.GoBack();

When you hit BackButton while MessageBox is shown - the result will be Cancel.

The code above is only a simple example and needs some improvements - which depend on your Navigation flow - after Navigating to LoginPage it would be nice to clear NavigationStack (delete previous page wich was logged out).

0
votes

What Aman and Romasz are saying is correct but instead of going through all this, you can do this:

1- After session expires, navigate to your login page:

NavigationService.Navigate(new Uri("/Login.xaml", UriKind.Relative));

2- Now, you can display a message box informing the user about the session expire thing without worrying about what the user presses. Or a more appealing/good looking solution would be displaying the message not inside a messagebox but inside a textbox below the sign-in/login buttons. That's how I do it!