Thursday, December 10, 2015

Handling Events in the Xamarin MessagingCenter - article

Tightly coupled systems are a nightmare to deal with. Having references everywhere causes all sorts of problems with reusability. Think about this in the standpoint of mobile systems where we would like to share code between iOS, Android and Windows .NET systems. Having to pass around a reference to a UIViewController or Activity/Fragment so that you can make some type of change can be a nightmare. iOS doesn't understand an Android Activity/Fragment, and Android doesn't understand a UIViewController.
What's a developer to do? Thankfully, there are a couple of answers to this problem. The first, and most obvious, solution is to use standard .NET/C# events. Remember, nearly every feature in the .NET Framework is a part of Xamarin products. The second possible solution is something that is Xamarin.Forms-specific: the Xamarin MessagingCenter, which I'll explore in this article.