Introduction

Xamarin.Forms code runs on multiple platforms, each of which has its own filesystem. This means that reading and writing files are most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.
Prerequisites
- Visual Studio 2017 or later (Windows or Mac)
Setting up a Xamarin.Forms Project
Start by creating a new Xamarin.Forms project. You will learn more by going through the steps yourself.
Create a new or existing Xamarin forms (.Net standard) Project with Android and iOS Platform. Choose the Mobile App (Xamarin. forms) project under C# and Mobile.
Name your app. You probably want your project and solution to use the same name as your app. Put it on your preferred location for projects and click "Create".
Now, select the blank app and target platforms - Android, iOS, and Windows (UWP).
Subsequently, go to the solution. There, you will get all the files and sources of your project (.NET Standard). Now, select the XAML page and double-click to open the MainPage.Xaml page.
You now have a basic Xamarin.Forms app. Click the Play button to try it out.
Create a Custom Webview
Here I'm going to create a custom webview inherited from webview for custom rendering to enable zooming.
CustomWebView.cs
- public class CustomWebView : WebView
- {
- }
Android Implementation
There are two ways in Android.
Use Platform Specific code
The following code snippets enable the default zooming in webview.
MyWebView.xaml.cs
- if (Device.RuntimePlatform == Device.Android)
- {
- webView.On<Android>().EnableZoomControls(true);
- webView.On<Android>().DisplayZoomControls(true);
- }
Custom Renderer
Here, create a custom renderer for enabling zooming in Android.
CustomWebViewRenderer.cs
- [assembly: ExportRenderer(typeof(CustomWebView), typeof(CustomWebViewRenderer))]
- namespace PDFPOC.Droid
- {
- public class CustomWebViewRenderer : WebViewRenderer
- {
- public CustomWebViewRenderer(Context context) : base(context)
- {
- }
- protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
- {
- base.OnElementChanged(e);
- if (e.NewElement != null)
- {
- var pdfView = Element as CustomWebView;
- Control.Settings.AllowUniversalAccessFromFileURLs = true;
- Control.Settings.SetSupportZoom(true);
- Control.Settings.BuiltInZoomControls = true;
- Control.Settings.DisplayZoomControls = true;
- }
- }
- }
- }


Darren AllenPosted Aug 21, 2022, 9:03 PM
Badly written!! More explanation....can't follow