MVVM Light Global Message registration? - mvvm-light

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.

Related

PRISM - CustomRenderer for NavigationPage

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!

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

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();
}
}

The Giant MVVMLight ViewModelLocator

I have a Main project A which has many dependencies like Project B, Project C etc... which are all assemblies/dll. Currently I have a ViewModelLocator in the ProjectA.App.xaml. This is the MVVMLight recommended way. The ViewModelLocator works fine but my problem is it is giant with all the ViewModel references from ProjectB, ProjectC etc... and it is hard to maintain.
I'm looking for a solution to segregate the ViewModelLocator to each projects ProjectB, ProjectC etc... and have their own ViewModelLocators. I also want to remove the global reference of ViewModelLocator which is the MVVMLight recommended way.
Any ideas?
Instead of using a single viewmodel locator, I created separate viewmodel locator for each module/project.

What's the base class of a Razor View in ASP.NET MVC3

I'm trying to have all my views inherit from a custom class so that I can add certain behaviour and values to all pages, but I'm having some issues. I tried subclassing System.Web.Mvc.WebViewPage but I'm forced to implement an Execute procedure that I don't know what it should do. Also, if I try to access the Context variable, I get a null reference (really weird). This leads me to think that I may have the wrong base class....
Any thoughts?
Diego, System.Web.Mvc.WebViewPage is the right base type (and you should have another class inheriting from System.Web.Mvc.WebViewPage<TModel> if you want strongly-typed views). You should mark your own class as abstract so that you are not forced to implement the Execute method.
Update: To configure all your views to use your custom base class, look into the ~\Views\Web.config file. Inside of it there's a Razor-specific section where you can use the pageBaseType attribute to configure your custom type.
As far as the Context property is concerned, it should be fully initialized once the view is executing. However, it might not be available if you try to access it too early (for example, from your classes constructor). When are you trying to access it?
The Execute method is something that is provided by the Razor compiler when your view is compiled. For example, given the following view file
Hello #Name!
The Razor compiler will behind the scenes generate the following class (this is a simplification, so the details might be off, but it should convey the point)
public class _Some_Generated_Class_Name_ : System.Web.Mvc.WebViewPage {
public void Execute() {
Write("Hello ");
Write(Name);
Write("!");
}
}
Then the framework calls the Execute method on your view class and your view gets executed.

Resources