PRISM - CustomRenderer for NavigationPage - xamarin.forms

I would like to ask if creating a custom renderer for NavigationPage would override Prism's NavigationService? since as per CustomPageTransition Prism uses Xamarin's built-in PushAsync/PopAsync -- correct me if I am wrong, this is the Navigation.PushAsync(page) right?
Thanks!

Related

ViewModel and leanback fragments

How can I use android.arch.lifecycle.ViewModel with leanback fragments? For example GuidedStepFragment extends android.app.Fragment which cannot be used in ViewModel instance creation via ViewModelProviders.of(fragment).get(viewModelClass) because method ViewModelProviders.of requires android.support.v4.app.Fragment.
Am I something missing or ViewModel can't be used for leanback fragments?
Leanback developers, hello? Why are you extending android.app.Fragment instead of android.support.v4.app.Fragment?
There is GuidedStepSupportFragment (extends android.support.v4.app.Fragment) in leanback starting from 27.1.0

Xamarin Forms with MvvmCross 5.7 First View not loaded

I have an Xamarin Application together with MvvmCross 5.7 and wanted to moved it completly to Xamarin Forms. It builds and starts as expected, but the first page isn't loaded.
I created the projects based this template: https://github.com/martijn00/MvxForms
Also I created a test project to see if something is wrong with my existing project: https://github.com/NPadrutt/XFTestProject
Can anyone point out what I am missing?
Either add a SplashScreen Activity who inherits from MvxSplashScreenActivity and with the method override:
protected override void TriggerFirstNavigate()
{
StartActivity(typeof(MainActivity));
base.TriggerFirstNavigate();
}
Or add these lines to the OnCreate Method in the MainActivity:
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
InitializeForms(bundle);
You don't neet to call startup.Start() in your MainActivity nor you need to init xamarin forms. It's done for you now (check RunAppStart method in mvvmcross sources for MvxFormsAppCompatActivity class).
From a quick glimpse at your GitHub repo, it looks like you're not decorating your view (i.e. WelcomView) with [MvxContentPagePresentation()] attribute (e.g. example from MvvmCross Playground). Add it in your WelcomeView.xaml.cs file and check if that helped
If it's a fresh project, you might want to consider using latest version of MvvmCross (v6). There's an awesome step by step guide to setup Xamarin.Forms with it by Nick Randolph

Xamarin Forms Prism Naming convention with subfolders

Is there a standered naming convention when making folders in a prism project ?
This works
ViewModals:
HelloWorldPageViewModel
View:
HelloWorldPage
App:
Container.RegisterTypeForNavigation<Views.HelloWorldPage >();
But for some reason , this does not work
I added the folling folders Login > Template >
ViewModals:
Login.Template.HelloWorldPageViewModel
View:
Login.Template.HelloWorldPage
App:
Container.RegisterTypeForNavigation<Views.Login.Template.HelloWorldPage >();
You have three options:
Change the naming conventions using the ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver. You can see an example in this blog post: http://brianlagunas.com/getting-started-prisms-new-viewmodellocator/
Or you can simply register your VM directly with ViewModelLocationProvider.Register<View, ViewModel>();
If you are using Xamarin.Forms simply provide the VM in the Container.RegisterTypeForNavigation<View, ViewModel>(); method
To the best of my knowledge Prism checks namepaces of ViewModels and Views.
So if your have a view it has to be under Views.Something , and if you want to have a viewmodel for it should be "ViewModels.SomethingViewModel"

What is the proper way to create control in Xamarin Form PCL?

What is the proper way to create control in Xamarin Form PCL?
In my class library I have "control" class not derived from any View, just a layout with some labels, scrollviews, logic etc.
I am using it in my pages in the same PLC in several places.
My question is - what is the proper way to wrap this "control" and use it in PLC pages?
I ended up having this control class to expose its root layout where I add all the child elements and subsequently add this layout to the children of page layout. This makes this class to be some sort of a builder of a part of UI of a page.
It looks like that using "View" as a base class requires me to add custom renderers to Android and iOS projects
which I don't need to do - all my UI functionality fits into PCL withot the need for any custom work.
I have a feeling that I am not doing it the right way.
Advise and/or link to the documentation on how to properly do it will be greatly appreciated.
It seems to me that you're actually hurting yourself by not wanting to use a View as a base class. I commonly use ContentView as a base class to create my own controls and it works great without the need for a custom renderer since ContentView already has its own renderers in iOS and Android. Something like this should do the trick.
public class MyContentView : ContentView
{
private Layout createLayout();
public MyContentView()
{
Content = createLayout();
}
}

MVVM Light Global Message registration?

I am using MVVM light to build my application and so far it has given excellent results. but I have this one small issue that i need to resolve.
Is there a way to globally register message listeners for each View model before they are initiated by the view. Something like a GlobalMessageRegistrationClass() ?
If you are using the MVVM Light tool kit, then you have to create a base Videmodel class which should be inherited from the MVVM Light tool kit class "ViewModelbase". Then all your view model class should be inherited from your custom viewmodel base class instead of MVVM light tool kit base class "ViewModelbase". In constructor of custom view model base class you can register for messages.

Resources