-
Notifications
You must be signed in to change notification settings - Fork 0
FormsMessageVisualizerService
Mark Smith edited this page Aug 26, 2016
·
3 revisions
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.
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<IMessageVisualizer>()
.Show("Error", "Houston, we have a problem", "OK);
}
}