Book Image

Cross-platform UI Development with Xamarin.Forms

By : Paul Johnson
Book Image

Cross-platform UI Development with Xamarin.Forms

By: Paul Johnson

Overview of this book

Table of Contents (22 chapters)
Cross-platform UI Development with Xamarin.Forms
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
In the Beginning…
Index

Setting up Windows Phone


Setting up the change of connectivity is simple on Windows Phone. In MainPage.xaml.cs, we need to subscribe to the NetworkAvailablityChanged event as follows:

DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(ChangeDetected); 

The ChangeDetected event is also simple, as shown in the following code:

void ChangeDetected(object sender, NetworkNotificationEventArgs e)
{
  MessageEvents.BroadcastIt("Connection",
  e.NotificationType==NetworkNotificationType.InterfaceConnected ?
  true.ToString() : false.ToString());
}

Finally, we need to implement the interface:

void ChangeDetected(object sender, NetworkNotificationEventArgs e)
{
  MessageEvents.BroadcastIt("Connection",
  e.NotificationType==NetworkNotificationType.InterfaceConnected ?
  true.ToString() : false.ToString());
}
class Connection : IConnectivity
{
  public bool NetworkConnected()
  {
    var rv = false;
    try
    {
      var InternetConnectionProfile...