在某个时候,我的应用程序需要在可用网络列表中显示,这没有问题:
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();
}但是,当用户再次移除屏幕时,我该如何检测呢?我需要一个OnReturnFromSystemScreen事件或类似的事情。
我做了一些测试:
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();
}但这还不够。所以任何想法都是有帮助的。
发布于 2014-11-11 08:09:13
我错过了最明显的激活和停用事件
// 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
}当显示我的系统屏幕时,将调用停用,当我返回时,调用已激活。
发布于 2014-11-07 09:26:53
我认为不存在从系统屏幕返回的事件,最接近的可能是使用OnNavigatedTo并检查NavigationEventArgs.NavigationMode的值Back,这将指示您是否使用back导航导航回页面。然后检查IsNavigationInitiator,这表明导航是否在应用程序中启动。如下所示:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.Back && e.IsNavigationInitiator == false)
{
txtHeader.Text = DateTime.Now.ToLongTimeString();
}
}还请参阅http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationmode(v=vs.95).aspx中NavigationMode的所有值。
发布于 2014-11-07 09:30:54
你的测试结果我不清楚。如果您在自己的代码中引发事件时遇到了困难:
“通常事件由类处理程序标记,而GotFocus事件不会引发以供该控件上的任何用户代码处理程序处理。”
您需要显式地覆盖OnGotFocus连体。
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
https://stackoverflow.com/questions/26797856
复制相似问题