private bool networkIsAvailable;
networkIsAvailable = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();//当前网络是否可用
if (!networkIsAvailable)
{
Dispatcher.BeginInvoke(() =>
{
MessageBoxResult res = MessageBox.Show("OK and Cancel", "您没有开启网络或者信号不好!,如需设置网络请选择“OK”", MessageBoxButton.OKCancel);
if (res == MessageBoxResult.OK)
{
ConnectionSettingsTask connectionSettings = new ConnectionSettingsTask();
//将连接设置更改为飞行模式
connectionSettings.ConnectionSettingsType = ConnectionSettingsType.Cellular;
connectionSettings.Show();
}
else
return;
});
}