问题
I am working with a WPF app for tablets with Windows 8.1. The app connects to SAP. In the settings I have to implement an option for synchronisation to only occur over a WiFi network.
How can I determine if the tablet is connected to WiFi or a cellular network? From my research I have found ways to do this on XP and Vista or using Universal Apps. How can I implement this feature using WPF and Windows 8.1?
回答1:
The following code should work, in c#
if(Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
{
//Mobile Data
}
else if(Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
{
//WiFi connection
}
else
{
//No network
}
来源:https://stackoverflow.com/questions/32501030/how-can-i-determine-whether-i-am-connected-to-wifi-or-a-cellular-network-wpf