In this blog, you will learn How to Capture ScreenShot Using DependencyService in Xamarin.forms
Introduction
Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files are the most easily done tasks using native file APIs on each platform. Alternatively, embedded resources are also a simpler solution to distribute the data files with an app.
DependencyService
DependencyService allows apps to call into platform-specific functionality from shared code. This functionality enables Xamarin.Forms apps to do anything that a native app can do.
DependencyService is a dependency resolver. In practice, an interface is defined and DependencyService finds the correct implementation of that interface from the various platform projects.
Xamarin.Forms apps need three components to use DependencyService
- Interface – The required functionality is defined by an interface in shared code.
- Implementation Per Platform – Classes that implement the interface must be added to each platform project.
- Registration – Each implementing class must be registered with DependencyService via a metadata attribute. Registration enables DependencyService to find the implementing class and supply it in place of the interface at runtime.
- Call to DependencyService – Shared code needs to explicitly call DependencyService to ask for implementations of the interface.
Prerequisites
- Visual Studio 2017(Windows or Mac)
Start by creating a new Xamarin.Forms project. You’ll learn more by going through the steps yourself.
Choose the Cross-platform App project under Visual C#-->Cross-platform in the New Project dialog.
Now Select the Blank App and Choose Portable Class Library(PCL).
You now have a basic Xamarin.Forms app. Click the Play button to try it out.
Setting up the User Interface.
Go to MainPage.Xaml and write the following code.
MainPage.Xaml
Click the Play button to try it out.
Creating Interface
Create - interface in Xamarin.Forms PCL.
Go to Solution—>PCL—>Right click—>New—>Interface—>IScreen.cs.
Now, write the following code.
IScreen.cs
Implementation per platform
Android Implementation
Go to Solution—>Android —>Right click—>New—>Class—> ScreenHelper.cs
Now, write the following code for Capture Current Screen.
ScreenHelper.cs
Call to DependencyService
In this step, call the DependencyService for your PCL.
MainPage.Xaml.cs
Click the Play button to try it out.
I hope you have understood how to Capture ScreenShot Using DependencyService.
Thanks for reading. Please share comments and feedback.
Thanks for this wonderful post. I used this and it is working perectly in my App. Is this possible that we can take Google map. i try but this return black screen. Hope you will help me for this
ReplyDeleteXamarin Monkeys: Xamarin.Forms - Capture Screenshot Using Dependencyservice >>>>> Download Now
Delete>>>>> Download Full
Xamarin Monkeys: Xamarin.Forms - Capture Screenshot Using Dependencyservice >>>>> Download LINK
>>>>> Download Now
Xamarin Monkeys: Xamarin.Forms - Capture Screenshot Using Dependencyservice >>>>> Download Full
>>>>> Download LINK 8G
Well, the fact of the matter is that there are many ways to accomplish this task. But, you may want to consider taking a screenshot of just a portion of your PC screen too. screenshot guide
ReplyDeleteEasy and high speed screenshot software download offers exist these days on the internet for your Windows 7, Vista, as well as for XP. how to screenshot on chromebook You can craft flawless and quality screen capture of the windows' round framed corners by making use of free screenshot software available online.
ReplyDeleteThanks for sharing this informative content , Great work
ReplyDeleteLeanpitch provides online training inScrum Master during this lockdown period everyone can use it wisely.
Advanced Scrum Master Training
Thanks for sharing this informative content , Great work
ReplyDeleteTo crack Agile coach interview : Scrum master interview questions
Thanks for this wonderful post. taking screenshot on chromebook is very easy. flow this for good Quality Screenshot.
ReplyDeleteXamarin Monkeys: Xamarin.Forms - Capture Screenshot Using Dependencyservice >>>>> Download Now
ReplyDelete>>>>> Download Full
Xamarin Monkeys: Xamarin.Forms - Capture Screenshot Using Dependencyservice >>>>> Download LINK
>>>>> Download Now
Xamarin Monkeys: Xamarin.Forms - Capture Screenshot Using Dependencyservice >>>>> Download Full
>>>>> Download LINK DO