Xamarin.Forms Features That Will Make Your Life Easier
-
Upload
virtualxamarin -
Category
Technology
-
view
269 -
download
2
Transcript of Xamarin.Forms Features That Will Make Your Life Easier
![Page 1: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/1.jpg)
Xamarin. Forms Features That Will Make Your Life Easier: DependencyService & MessagingCenter
Andres Castro
![Page 2: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/2.jpg)
My Background
Andres Castro• ASP.NET MVC
• ASP.NET WEBFORMS
• Web Services
• Xamarin
![Page 3: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/3.jpg)
Who Is Bluetube
• Established in 1999
• Award-Winning Solutions
• Experts with Technology and Usability
• Enterprise Corporations & Non-profit Clients
• Premier Xamarin Consulting Partner
• Xamarin Test Cloud Consulting Partners
Bluetube designs and
builds enterprise mobile
apps & responsive
websites.
![Page 4: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/4.jpg)
Dependency Service
What is it?
The Xamarin.Forms Dependency Service is a simple
dependency resolver that simplifies how platform specific
features are implemented.
Basically, it allows you to register classes which will then be
pre-initialized for you upon request. It removes the need for
you to “new” every time you need to use that class.
![Page 5: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/5.jpg)
Dependency Service
How does it work?
There are 3 steps necessary to successfully using the
dependency service.
1. Create an interface that will define how each platform
should be implemented.
2. Register each platform-specific implementation of the class
above.
3. Use the implemented interface using
DependencyService.Get<T>
![Page 6: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/6.jpg)
Dependency Service
Creating the Interface
As an example, I will be creating a interface that allows you to
open the Phone Dialer from within your app.
![Page 7: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/7.jpg)
Dependency Service
Registering the Android Implementation
![Page 8: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/8.jpg)
Dependency Service
Registering the iOS Implementation
![Page 9: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/9.jpg)
Dependency Service
Using the Code
![Page 10: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/10.jpg)
Messaging Center
What is it?
The Xamarin.Forms Messaging Center allows you to send and
receive “Messages” without knowing who they are going to or
who they are coming from.
It is very similar to using Event Handlers, the only difference is
that you are hooking into the Messaging Center.
![Page 11: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/11.jpg)
Messaging Center
How does it work?
There are three parts to using the Messaging Center
1. Subscribe – Subscribes the messaging center to listen to a
certain message. You can then perform an action based on
that message.
2. Send – Sends a message through the messaging center so
that any subscribed classes receive the message.
3. Unsubscribe – Stops listening to any messages that might
come through.
![Page 12: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/12.jpg)
Messaging Center
Example
Lets extend the existing Phone Dialer Example to navigate us
back, which will take us to a new page after the call code has
executed.
![Page 13: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/13.jpg)
Messaging CenterLet’s first create a message class that will help to wrap data
we want to send.
![Page 14: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/14.jpg)
Messaging Center
Subscribing to the Message
![Page 15: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/15.jpg)
Messaging Center
Sending the Message
![Page 16: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/16.jpg)
Recap
– Covered what the Dependency Service is and how to
implement it.
– Saw how to call platform specific code using the
Dependency Service.
– Covered what the Messaging Center is and how to
implement it.
– Used the Messaging Center to implement navigation inside
the app.
Dependency Service & Messaging Center
![Page 17: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/17.jpg)
References– http://developer.xamarin.com/recipes/android/fundam
entals/intent/launch_the_phone_dialer/
– http://developer.xamarin.com/recipes/ios/shared_reso
urces/phone/dial-phone-uri/
– http://developer.xamarin.com/guides/cross-
platform/xamarin-forms/dependency-service/
– http://developer.xamarin.com/guides/cross-
platform/xamarin-forms/messaging-center/
![Page 18: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/18.jpg)
![Page 19: Xamarin.Forms Features That Will Make Your Life Easier](https://reader031.fdocuments.us/reader031/viewer/2022032010/55a6c0611a28ab3b688b47ee/html5/thumbnails/19.jpg)
Thank you to our sponsors!