question

hosseintavakoli-7723 avatar image
0 Votes"
hosseintavakoli-7723 asked JessieZhang-2116 answered

connect xamarin forms click method to android method

I use Camera2forms

I have a button in MainPage.xaml , also I have a method called "OpenCamera(...)" in Camera.Droid.

How can I Call "OpenCamera(...)" method from MainPage.xaml.

picture


dotnet-xamarin
capture.png (60.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered

Hello,


Welcome to our Microsoft Q&A platform!


Yes, if you want to invoke native platform functionality in forms, you can use Xamarin.Forms DependencyService to achieve this function just @alessandrocaliaro said.

The DependencyService class is a service locator that enables Xamarin.Forms applications to invoke native platform functionality from shared code.

The process for using the DependencyService to invoke native platform functionality is to:

  1. Create an interface for the native platform functionality, in shared code. For more information, see Create an interface.

  2. Implement the interface in the required platform projects. For more information, see Implement the interface on each platform.

  3. Register the platform implementations with the DependencyService. This enables Xamarin.Forms to locate the platform implementations at runtime. For more information, see Register the platform implementations.

  4. Resolve the platform implementations from shared code, and invoke them. For more information, see Resolve the platform implementations.

And there is a sample included in above document, you can check it here: https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/dependencyservice/


Best Regards,


Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.



Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

alessandrocaliaro avatar image
0 Votes"
alessandrocaliaro answered Stesvis-5434 commented
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@hosseintavakoli-7723 I agree with @alessandrocaliaro and I would add that in this case you will need to make an event in your code behind and call the dependency service from there.

0 Votes 0 ·