WPF: Checking internet connection
Create class ConnectionInternet and add " Using Windows.Networking.Connectivity.
public class ConnectToInternet
{
public bool _ConnectInternet()
{
ConnectionProfile internetprofile = NetworkInformation.GetInternetConnectionProfile();
if (internetprofile == null)
{
return false;
}
var level = internetprofile.GetNetworkConnectivityLevel();
return level == NetworkConnectivityLevel.InternetAccess;
}
}
We finished the part class. Now, we will come back to xaml.cs
MainPage class or NavigationHelper_LoadState. We will check the internet here.
if (ConnectToInternet._ConnectToInternet())
{
/*Here code*/
}
else
Messages._ShowMessages("Verify you internet connection!!!");
Messages._ShowMessages is one class to show error.