Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to use prism forms eventaggregator with xamarin forms?


Asked by Zaiden Simon on Dec 15, 2021 FAQ



After initializing the Xamarin.Forms app in OnLaunched () method of native App.xaml.cs, subscribe in the constructor of MainPage.xaml.cs, You can find the complete working sample here: https://github.com/PrismLibrary/Prism-Samples-Forms/tree/master/UsingEventAggregator
Also Know,
If you are building a Xamarin.Forms app, it should be a no-brainer that you use MVVM pattern for your code base. It should also be a no-brainer that you give Prism.Forms a try. It makes development fast and code easy to maintain with its plethora of built-in services such for navigation, dependency injection, alerts, events, etc.
Indeed, Events created with the Prism Library are typed events. This means you can take advantage of compile-time type checking to detect errors before you run the application. In the Prism Library, the EventAggregator allows subscribers or publishers to locate a specific EventBase.
Also,
To subscribe to an event published in Xamarin.Forms app at the platform level, resolve the IEventAggregator from the Xamarin.Forms.App () instance before loading it. After initializing the Xamarin.Forms app in FinishedLaunching () method of AppDelegate.cs, After initializing the Xamarin.Forms app in OnCreate () method of MainActivity.cs,
In respect to this,
Prism provides an implementation of a collection of design patterns that are helpful in writing well-structured and maintainable XAML applications, including MVVM, dependency injection, commands, Event Aggregator, and others. Prism's core functionality is a shared code base in a Portable Class Library targeting these platforms.