Category: Xamarin
-
XamarinForms – Overriding a ContentPage with a custom PageRenderer on Android
The short version:
If you want to have default behavior on all platforms except for Android. Do the following
- Create your content page with all of it’s goodies
- Create a custom PageRenderer
- In the OnElementChanged function
- Cast the Context property of the renderer to the Activity type associated
- Take that value and execute the SetContentView method while passing in your new view!
The awesome story version:
I’m building a Xamarin Forms application which has a default implementation in most platforms and a special snowflake behavior on Android. While working through the Xamarin documentation I realized that custom renderers were the way to go.
The default behavior for all platforms is performed through a WebView, which has some custom logic when pages are navigated. While the functionality still works, it doesn’t feel seamless. However, in Android there is already native functionality that really improves the user experience, so I wanted to make sure that if I was on the Android platform, … Read the rest