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/ .
Related
For Cordova iOS and Cordova Android it is possible to create plugins that create native UI on top of your app - you just include the libraries in your plugin and execute their API. Example for Android InAppBrowser.
For Cordova Windows, the native code is HTML and Javascript, hence the InAppBrowser plugin also adds a standard HTML tag for a Webview (or even plain Iframe) to get the same effect.
But you can also create plugins for Cordova Windows that use C# or C++ native code via a Windows Runtime Component. A public example is the globalization plugin that uses a .winmd file to offer APIs to the Javascript code (source code for this). This works great and is pretty awesome.
Unfortunately all the plugins that I could find use this C#/C++ native plugin mechanism only to receive some method call, do something with the parameters and return some data. None of those open any windows or create any other GUI (that might for example be offered by an external C# SDK).
How can one create a plugin for Cordova Windows that creates User Interface with native (C#, C++) code? Is this possible at all?
Got a response in a Apache Cordova mailing list that I am reproducing here:
Unfortunately, No. C#/C++ Portable Class Library ( PCL ) code cannot
render on top of the web component.
The libraries that you can use are limited in PCLs and for projects
targeting Windows Store it is not possible to render UI.
If the entire cordova-windows platform were re-architected to be a C# or
C++ based application, with a native webview container in which to render,
then everything is possible. This is a long risky road though ...
everything from the cordova.js and the bridge would have to change, and
every plugin would need to be rewritten.
Is it possible to create common controls that can be used for both UWP and WPF applications?
Tried digging over the .NET and found out that code can be shared across them using .NET Standard but what about XAML controls/UI ?
You can't directly use WPF controls in UWP apps, as there are many features of WPF XAML which are not yet available in UWP. So direct forward compatibility is not available here. Evenso, upgrading existing WPF controls to UWP should not be too hard, usually all it takes is to rewrite some parts of XAML but the actual business logic behind them can be ported 1:1, as most is covered by .NET Standard.
However, at Build 2018 Microsoft announced UWP XAML Islands functionality, that will allow developers to upgrade the UI of WPF apps to modern UWP design, including Fluent Design System features. In the near future you will be able to do this with all UWP controls (including custom), once the APIs are ready, but currently you can at least use the modern UWP WebView control in WPF, which is part of the Windows Community Toolkit.
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.
Sorry, I don't have much experience in programming and English and my question might be awkward. It relates to Windows 10 applications for classic desktop and touch screens.
I want to add a nice-looking touch-oriented Modern-style UI to my non-Visual Studio application. It is possible to call an external .NET assembly from my app and use its public constructors, methods, properties, and handle its events.
So I’ve created a new WPF User Control Library project in Visual Studio, replaced default User Control with a new Window, and built a dll file. Now I can use it in my app as described above. Everything seems to work fine.
Here are the questions:
Am I doing it right? Is building a dll from WPF project the only way
to make a UI dll that can be used in external applications?
How can I make the UI looks and acts like Windows Universal Apps (at least I want it to respond screen rotation)? As I understand I
cannot build a dll from Universal App projects and I have to create
WPF window, make it full screen, and add appropriate UI elements.
Is it possible to use Windows 10 contracts and extensions in such UI
dll?
If you want to share your code between different programs, you have to make it a shared library which is dll in windows. I don't know the other two questions.
I'm thinking about starting to use Xamarin, is it possible to take a full-screen WPF project and use it on iOS and Android ?
No. Xamarin.Android and Xamarin.iOS expose the UI of the relevant platforms - you can't just use WPF on them.
However, if you separate out your "business logic" from the UI logic in your application, you may well be able to use the same business logic project, and just create new UI projects (one per platform). Of course, that relies on your "business logic" only requiring functionality which is available on Xamarin; more generally you'd want to create a Portable Class Library with that code in.
No this is not possible. You have to use the Native API's for User Interface on both IOS and Android when you use Xamarin.
You can definitely share a lot of code, but WPF will not work.
No. Xamarin relies on each platform's native UI stack. You cannot take a WPF UI (or a Winforms or Silverlight UI) and run it on iOS or Android. What you CAN do is take the underlying core of your WPF project (domain, services, data, business logic) and use Xamarin to create an iOS and/or Android native UI on top of it.
WPF is only supported on Windows - it's not even supported on other platforms with desktop APIs for Mono.
In general, with Xamarin, the approach is you share "logic" code, but use native UI projects for each platform.