Reader small image

You're reading from  Cross-platform UI Development with Xamarin.Forms

Product typeBook
Published inAug 2015
Reading LevelBeginner
Publisher
ISBN-139781784391195
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Paul Johnson
Paul Johnson
author image
Paul Johnson

Paul Johnson has been writing software since the early 1980s on machines ranging from the ZX81 and servers to his trusty Mac, and has used more languages than he can remember. He is a qualified scuba diver and college lecturer. Paul lives with his wife, kids, and pets, and listens to an inordinate amount of rock and metal on Primordial Radio. This is his third book for Packt.
Read more about Paul Johnson

Right arrow

Setting up the event system and interface


The interface only needs to be something as simple as the following code:

namespace connectivity
{
  public interface IConnectivity
  {
    bool NetworkConnected();
  }
}

Note

The source for the connectivity part of the chapter can be found in Chapter13/Connectivity.

To track the state of the connection, a bool variable is set up in App:

public static App Self {get; private set;}

public bool IsConnected {get; private set;}

public App()
{
  App.Self = this;
  IsConnected = DependencyService.Get<IConnectivity>().NetworkConnected();

The reason why IsConnected is set to private set; is because the listener for the event change is in App. We will keep all the connectivity parts in one place.

The handler for the event is also fairly simple, although we need to also broadcast back to the platform to send an internal notification, as shown in the following code:

public UIChangedEvent MessageEvent { get; set;}
MessageEvent = new UIChangedEvent();

MessageEvent...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Cross-platform UI Development with Xamarin.Forms
Published in: Aug 2015Publisher: ISBN-13: 9781784391195

Author (1)

author image
Paul Johnson

Paul Johnson has been writing software since the early 1980s on machines ranging from the ZX81 and servers to his trusty Mac, and has used more languages than he can remember. He is a qualified scuba diver and college lecturer. Paul lives with his wife, kids, and pets, and listens to an inordinate amount of rock and metal on Primordial Radio. This is his third book for Packt.
Read more about Paul Johnson