Same UI for all platforms in Mvvmcross Xamarin - user-interface

Hello All, Can i code one UI for all platforms using Mvvm Cross framework in Xamarin?
Like i code for a generic UI which can generated for different platforms Android,IOS,Windows.
I saw Xamarin Forms giving some thing like this , but what about MVVMCross.

So if i conclude in simple sencario , since xamarin forms uses Mvvm so its better to use xamarin forms instead of mvvmcross for one single Ui

No, Mvvmcross doesn't provide UI automagically. View is platform specific while models and viewmodels are platform independent.
With Forms all three are platform independent. To make this work Forms added another layer, called Renderer (which is platform specific). Out of the box there is a bunch of renderers, then there is 3rd party community (specially Forms Labs) and finally, you can make your own renderers or extend existing ones.

Related

Can I share UWP viewmodels with xamarin iOS?

What is realistic amount of code share between Xamarin and UWP?
I have app which has following layers:
1. UWP platform specific apis
2. Messaging protocol based on these apis
3. Services
4. ViewModels
5. Xaml Views communicating with INotifyPropertyChanged and ICommand
I understand that obviously 1 (platform specific apis) an 5 (xaml views) cannot be shared. Layers 2 and 3 should be ok. What about ViewModels? I think it should be possible to achieve this using thin layer of viewModel adapter, is this realistic?
Also I am not planning to use xamarin.forms.
The answer depends on your application.
UWP has many specific APIs that as such don't work on Xamarin. They are not necessary related to views only but can be also related to viewmodel code. If your viewmodel is a separate .Net standard project then you can reuse it completely, but as it is not always the case with UWP apps you can probably reuse just most of the code.
The second part comes down to actually using this viewmodel in iOS/macOS project. As you don't want to use XAML (Xamarin.Forms), there is no data binding provided. Basically you have to do whole data binding manually. Some MVVM frameworks may help you in that, but if you ask me they should be called 'helpers', not frameworks.

Bind/set short text data from Android MainActivity.cs to a shared Xamarin Forms Label?

Is there a way to define a Label in Xamarin Forms (XAML or code-behind) AppXYZ that can be updated from the Xamarin Android AppXYZ.Android: MainActivity.cs and AppXYZ.iOS:Main.cs? i.e. upon an event in Android (e.g. BlueTooth) set a short text in a common Forms elements? After viewing many example, no clarity yet. MessageCenter perhaps?
In Android Project: MainActivity.cs (for example):
FormsAppXYZ.LabelXYZ.Text = "Updated string";
If not possible, then proper way to do this with Xamarin Android Native ? appreciated since I'll have to mix in the label into a shared Xamarin Forms Tabbed GUI.
Depending on how much Bluetooth work you need to do, my first suggestion would be to use MessagingCenter as you have already alluded to.
The other obvious approach would be to use a third party plugin, as I don't believe Xamarin have released one. I am currently aware of these two:
https://github.com/aritchie/bluetoothle
https://github.com/xabre/xamarin-bluetooth-le

Xamarin Forms IoC containter + navigation service

Does Xamarin.Forms have a built-in IoC navigation service? I mean something like Prism, where you could register your routes.
If yes - where is the documentation?
If not - will Xamarin.Forms have a built-in navigation service in near future?
Also - if not - what would be the best MVVM fw for Xamarin.Android, Xamarin.iOS, Xamarin.WinXYZ and Xamarin.Forms? And why?
It seems to me that it comes down to battle between Prism and FreshMVVM - this brings me to my most important questions:
Which of these two is performing better? (Which one is faster?)
Which of these is more likely to lead the way of MVVM frameworks considering mobile development in the future?
No Xamarin Forms does not offer navigation like Prism. They had a goal of making the built in Navigation similar to Prism, but that has since disappeared from their roadmap. There is also no direct IoC concept built directly into Xamarin Forms.
If you are developing native UI's then Prism probably isn't for you as it is purpose built for Xamarin Forms. In that case I might say you should look at MvvmCross. It is battle tested in a lot of classic Xamarin apps.
If however you are developing with Xamarin Forms, then Prism would be the best to use. My opinion may be biased, but it's also the public opinion of many of those on the Xamarin team. Remember Prism was originally started by the Microsoft Patterns and Practices team. While Prism for Xamarin Forms was started after that, the foundation of what Prism is and how it works, helps keep developers developing using proper MVVM patterns.
Question 1: Yes, Xamarin.Forms have a built-in navigation service.
Question 2: Xamarin.Forms navigation
Edit 2 for question 1: No, there is no IoC Navigation built in Xamarin.Forms framework.
But if you want some IoC navigation maybe this a good one: Xamarin Forms - View Model First Navigation avoiding big frameworks like Prism, MVVMLight or MVVMCross. If not this frameworks works well for this purpose.

Xamarin - mixing Forms and Storyboards

Is it possible to mix iOS Storyboards and Xamarin Forms within one application? I have a bunch of views that are easier to be created in Forms, but some which are heavily customized so we would need to create some of them in native code.
I would like to use Storyboards to create the native parts, but can't seem to find a way to navigate from a Forms page to a Storyboard and vice versa.
I don't mind doing it from code, just need to know the direction to look into and if it's even possible.
You can create native views using the concept of Custom Renderers (see links below). The idea is that you create a Xamarin Forms Control that's shared between all platforms and which old common properties (like colors, general data etc), and do the native rendering on the iOS/Android/WP projects.
So, for your storyboard, you can create it usign Xamarin.iOS, and render using a Custom Renderer. The link posted by #GSerg in the comments have some information and examples, but you can take a closer look at the oficial documentation as well:
Introduction to Custom Renderers
Customizing Controls on Each Platform
Customizing Control Rendering in Xamarin.Forms (video)
Also, for more real world examples you can take a look at the Xamarin Forms XLabs project.
Thanks to Rafael Steil's answer. I looked at the links and a few more samples.
Notably:
Custom Renderer Map
Using Xamarin Forms alongside Storyboard
And I created a sample project to show the back-and-forth navigation between Xamarin Forms and pages created in Storyboards. You can find it over here:
Xamarin Forms Mixed with Native

Is possible to do sliding drawer in xamarin cross platform?

I am working in xamarin pcl project , I am trying to keep sliding drawer in my pcl project but i dont know how to do that .
Are you using Xamarin.Forms?
If not, i would advice to use a framework like MvvmCross (https://github.com/MvvmCross/MvvmCross)
This would enable you to split the actual implementation of the drawer / hamburger menu into the different UI projects like iOS and Android(maybe WP8 too).
Since those platforms all behave differently, for example Android uses Fragments which are replaced inside the activity containing your navigation drawer, you should use a custom presenter to determine where you want the specific platform to navigate to. You can find more information on that topic here: http://slodge.blogspot.co.uk/2013/06/presenter-roundup.html

Resources