Windows Phone 7 开发之检查手机网络

webphp 13年前
     <pre class="brush:c#; toolbar: true; auto-links: false;">using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; using System.Net.NetworkInformation; using Microsoft.Phone.Net.NetworkInformation;    namespace checknet {     public partial class MainPage : PhoneApplicationPage     {         private bool networkIsAvailable;         private NetworkInterfaceType _currentNetworkType; //网络连接的类型           public MainPage()         {             InitializeComponent();         }           private void button1_Click(object sender, RoutedEventArgs e)         {             networkIsAvailable = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();//当前网络是否可用             _currentNetworkType = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;//获取当前网络的类型               if (networkIsAvailable)             {                 Message.Text = "联网状态";                 Message.Background = new SolidColorBrush(Colors.Green);             }             else             {                 Message.Text = "断网状态";                 Message.Background = new SolidColorBrush(Colors.Red);             }                switch (_currentNetworkType)             {                 case NetworkInterfaceType.MobileBroadbandCdma:                     netname.Text = "Cdma网络";                     break;                 case NetworkInterfaceType.MobileBroadbandGsm:                     netname.Text = "Csm网络";                     break;                 case NetworkInterfaceType.Wireless80211:                     netname.Text = "Wireless网络";                     break;                 case NetworkInterfaceType.Ethernet:                     netname.Text = "Ethernet网络";                     break;                 case NetworkInterfaceType.None:                     netname.Text = "网络不可用";                     break;                 default:                     netname.Text = "其他的网络";                     break;             }                }     } }</pre>    <br />