System Screen Return Detection

At some point, my application should show up in the list of available networks, here's the problem:

private void ShowConnectionSettings()
{
    Debug.WriteLine("ShowConnectionSettings()");

    //Use the ConnectionSettingsTask to bring up the connection settings
    var connectionSettings = new ConnectionSettingsTask();

    // We are using the Connection Settings page for AirplaneMode.
    connectionSettings.ConnectionSettingsType = ConnectionSettingsType.WiFi;
    connectionSettings.Show();
}

      

But how can I tell when the user has deleted this screen again? I need an event OnReturnFromSystemScreen

or something.

I ran some tests:

private void PhoneApplicationPage_GotFocus(object sender, RoutedEventArgs e)
{
   txtHeader.Text = DateTime.Now.ToLongTimeString();
}

private void PhoneApplicationPage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
    txtHeader.Text = DateTime.Now.ToLongTimeString();
}

    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
        txtHeader.Text = DateTime.Now.ToLongTimeString();

    }

      

But this is not enough. So any flaws would be helpful.

+3


source to share


3 answers


I missed the most obvious events with activated and deactivated

// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
   //do stuff
}

// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
   //do stuff
}

      



when my system screen is displayed. Called deactivated and when I return the call is activated.

+1


source


I don't think there is an event to return from the system screen, the closest thing you can do is probably use OnNavigatedTo and check the NavigationEventArgs.NavigationMode for a value Back

that will indicate if you navigated to the page using back navigation. And then also check the IsNavigationInitiator which indicates if Navigation has started in the application. Like this:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    if (e.NavigationMode == NavigationMode.Back && e.IsNavigationInitiator == false)
    {
        txtHeader.Text = DateTime.Now.ToLongTimeString();
    }
}

      



Also see http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationmode(v=vs.95).aspx for all NavigationMode values.

+1


source


The results of your tests are not clear to me. If you're having trouble getting the event raised to your own code:

"Typically, the event is marked with a class handler, and the GotFocus event is not raised to be processed by any custom code handlers on this control."

You need to explicitly override the OnGotFocus event handler.

http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.gotfocus.aspx http://msdn.microsoft.com/en-us/library/windows/apps /windows.ui.xaml.controls.control.ongotfocus.aspx

0


source







All Articles