Xamarin.Forms with FreshMVVM. Adding new property to FreshBasePageModel class

125 Views Asked by At

My project (Xamarin.Forms with FreshMVVM) contains multiple pages and I need property isBusy. My PageModels inherit from FreshBasePageModel class. I'm looking for a way to extend FreshBasePageModel class to add IsBusy property.

Is there a way to do this? Multiple inheritance is not allowed in C#. Using extension methods i only add methods (not properties).

There is an idea to add a new class (FreshBasePageModelExt) that inherits from the FreshBasePageModel class, and use this new class as a base class for my PageModels, but perhaps there is a more elegant solution.

1

There are 1 best solutions below

1
Michael O On

Mine looks like this

    public class BaseViewModel : FreshBasePageModel
    {
            public bool IsBusy { get; set; }
            public string Title { get; set; }
    }

By creating this BaseViewModel and inheriting your viewModels from this will give you these attributes and then you have them in all your ViewModels.