Embedding Xamarin Forms or native embedding - c#

I will make an app where I need the native map. Either I do the app with Xamarin native and Embedding Xamarin.Forms in Xamarin Native on all pages without the page with the map. Or if it's possible I'll do an Xamarin Forms app and embedding the native map control, if it's possible? I read Adding Platform-Specific Controls to a Xamarin.Forms Layout but is the map included? Or is it only "small" controls as the label?
What should I use?

Well Native Embedding is hard to implement ( you basically need to use the shared project instead of PCL), therefore for many it is easier to user CustomRenderers.
Xamarin.Forms Embedding in the otherhand, is still preview looks like easy to use , but to be honest I have no idea what advantages it gives us. Like if we are making a native app why do we need to have a xamarin.forms loaded to our projects and not only it will make our app bigger but it will make it harder to follow.
The way I see it from your question is to use the maps given by Xamarin.Forms here and you can access it's custom renderer if it is necessary. Or use TKCustomMap which they have already extended the map

I was helping in a project when developer did the follow and it seems worked for him. He did Xamarin Forms, created
public class CustomMap : Map
where Map is Xamarin.Forms.Maps.Map. Then created custom renderers
[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
namespace CustomRenderer.iOS
{
public class CustomMapRenderer : MapRenderer
and
[assembly:ExportRenderer (typeof(CustomMap), typeof(CustomMapRenderer))]
namespace CustomRenderer.Droid
{
public class CustomMapRenderer : MapRenderer, GoogleMap.IInfoWindowAdapter, IOnMapReadyCallback
Then you can do a lot of things with CustomPins, InfoWindow, etc

You can embed any native control in a xamarin forms app. This is a feature already released while the xamarin.forms embedding into a native app is still in preview.
I would either embed the native map as you suggested or do a custom renderer for the map control already available in forms.

Related

Using Native Page in Xamarin Cross Platform Application

I have Xamarin Cross Platform Application in Visual Studio 2022. I have a Main Page where i want 2 buttons.
"Take me to Android Page" Button
"Take me to iOS Page" Button
I want to create a sample NATIVE page specifically in Android Project of this Cross Platform Application and one sample NATIVE page specifically in iOS Project within this Xamarin Cross Platform Application.
When I will click on "Take me to Android Page Button", it should take me to Natively designed Page of Android and when I will click on "Take me to iOS Page Button" then it should take me to Natively designed page in iOS Project.
I hope anyone can give me any reference or sample codes to achieve this goal.
Thank You
Xamarin.Forms is designed to prevent the need to design each page for both platforms by using XAML to define shared layouts rendered at runtime using native controls. If you can expand your question to include reasons why you need to define fully native page layouts for each platform, that will help better inform answerers.
If you need the ability to create custom controls for each platform, consider custom renderers which will allow you to define platform-specific behavior for individual views in your XAML pages.
When I will click on "Take me to Android Page Button", it should take
me to Natively designed Page of Android and when I will click on "Take
me to iOS Page Button" then it should take me to Natively designed
page in iOS Project.
You can first find out what Xamarin Forms is and how it works.
From document What is Xamarin.Forms?,we know:
Xamarin.Forms is an open-source UI framework. Xamarin.Forms allows
developers to build Xamarin.Android, Xamarin.iOS, and Windows
applications from a single shared codebase.
Xamarin.Forms allows developers to create user interfaces in XAML with
code-behind in C#. These interfaces are rendered as performant native
controls on each platform.
And part Who Xamarin.Forms is for mentions that :
Xamarin.Forms is for developers with the following goals:
Share UI layout and design across platforms
Share code, test and business logic across platforms.
Write cross-platform apps in C# with Visual Studio.
So, the requirement you mentioned above is not invalid.
In addition,if you want to use native controls of the target platform in xamarin forms, you can use Xamarin.Forms Custom Renderers to achieve this.
Xamarin.Forms user interfaces are rendered using the native controls
of the target platform, allowing Xamarin.Forms applications to retain
the appropriate look and feel for each platform. Custom Renderers let
developers override this process to customize the appearance and
behavior of Xamarin.Forms controls on each platform.
Note:
We have Payment Gateway SDK for Android specific only that's why we
need to use Native forms. Can you suggest or give me some hint how we
can use them ?
Xamarin.Android offers two ways to use these libraries:
1. Create a Bindings Library that automatically wraps the library with
C# wrappers so you can invoke Java code via C# calls.
2. Use the Java Native Interface (JNI) to invoke calls in Java library
code directly. JNI is a programming framework that enables Java code
to call and be called by native applications or libraries.
For more details, check: https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/ .

How can I render .obj model in Xamarin.Forms?

I have a .obj file that has a 3D body in it and I want to render it in a Xamarin.Forms app that already exists(made with MvvmCross), so I just want to create a new ContentPage that has the rendered body. The user should be able to view the body from different perspectives and maybe click on it to highlight some parts, but that's it.
I found out about UrhoSharp and I also know that I can use Metal and Vulkan bindings for Xamarin, but as I'm a beginner in 3D apps I don't know which one would be best for my scenario, that's why I would like someone to point me in the right direction for this scenario. For UrhoSharp I found this loader which only works on Windows 10, the Android app doesn't load anything and the iOS app renders the body but I can't move the camera around it.
Xamarin forms is good for making apps that are like "Forms" in which you fill out some information and submit.
The best way to do more 3D work is using Xamarin Native, Unity or if you want it to be a small part of your Xamarin Forms app, you can simply create a Custom 3D Renderer in Xamarin Forms.
The beauty of Xamarin is that you can access all the native APIs, so you would just follow tutorials on using the native APIs to access those OBJ files. For iOS, you would just be looking for a tutorial on how to use ARKit and then make small tweaks to add the obj file like this.
Do the same thing for android!

Native Page in Xamarin.Forms

I apologize in advance for my question, but I start with Xamarin and need help to create a particular architecture.
I should use Xamarin forms with MVVM Light , but with a large part of native pages (UWP).
For this, I wondered if I had to place my View-Models in the portable class or in the UWP Project ? And if in the portable class, what navigation use to navigate between my native pages ?
The Logic should be placed inside the shared code so put your ViewModels inside the portable or shared project.
For navigation between pages you could use:
conditional compilation
if mobile
navigation droid/iOS
else
navigation UWP
(Use with underscores, entering here is using formatting, see link
Condotional Compilation for more details)
DependencyService as described here DependencyService
I'm sure there are other ways but I think DependencyService is the most elegant, as those #if#else stuff makes the code confusing and unreadable.

Platform-specific User-controls

Hello all great people in here
I am heading for creation of a Xamarin.Forms app.
I have taken a look on this link https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/entry/, where they are going to make the renderer for components platform-specific.
An example can be TwinTechs Controls, which is only available for iOS and Android. How can this be done?
Is that possible? And if it, how?
The Renderer class is the custom platform-specific that you need to customize per platform.
In that particular example they are looking at changing an existing renderer.
You will be more focused in writing your own platform-specific components from scratch.
To do so you will want to inherit from ViewRenderer and supply reference to the View and also the platform-specific native element that will be the root of the control on the platform level.
Don't forget to export the renderer also, for it to be used in the rendering process of the page in Xamarin.Forms, from the platform level along the lines:-
[assembly: ExportRendererAttribute(typeof({ViewNameHere}), typeof({RendererClassNameHere}))]
There is a useful tutorial on writing custom renderers here that will help you further.

Is there a xamarin component that will handle PIN entry?

I see there is an iOS and iPad, PIN Code Control xamarin component, that will give your a programmatic numeric keypad for PIN Entry. Short of coding the entire thing using C# in Xamarin I would prefer to find a component.
I need a PIN code control, xamarin component that is cross platform, which is the purpose of xamarin forms. We will be using this on Android and iOS devices.
Has anyone see such a component on Xamarin's Component Store and I am using the wrong search terms, PIN, Keypad, Numeric?
For future googlers: you might be interested in a small Xamarin.Forms library XamarinFormsPinView. I'm the author.
It's not very configurable, but should fill most common requirements.
Sorry, I have not seen a component that does what you need.
This Xamarin.Forms calculator sample might be a useful starting point for writing a custom one (since it already implements a numeric keyboard entry with display and backspace).
Obviously there's a lot of styling work required to get it looking like any of the native PIN entry screens - but it should save you writing from scratch.
If you need attractive xamarin forms pin passcode form with high control, check out this repo. It is not a library and it does not use MVVM models. It is just .XAML page with code behind it.
https://github.com/Akezh/XamarinFormsPinPassword

Categories