Skip to content
This repository was archived by the owner on Aug 27, 2020. It is now read-only.

FormsMessageVisualizerService

Mark Smith edited this page Aug 29, 2016 · 2 revisions

FormsMessageVisualizerService

The FormsMessageVisualizerService provides a simple wrapper around the Xamarin.Forms Page.DisplayAlert functionality to make it conform to an abstraction - IMessageVisualizerService. This breaks the dependency in a View Model and allows it to be tested properly.

Usage

To use this, you must associate this type with the interface. If you are using the DependencyService, you can do that in your App constructor:

public class App
{
   public App()
   {
      DependencyService.Register<IMessageVisualizerService, FormsMessageVisualizerService>();
   }
   ...
}

Then you can retrieve it in your View Model:

public class MyViewModel
{
   IDependencyService ds;
   ...
   void OnError() {
      ds.Get<IMessageVisualizerService>()
          .Show("Error", "Houston, we have a problem", "OK);
   }
}
Clone this wiki locally