-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Protects you with type-safety, everywhere
Core BTS's Shield MVVM is a .NET MAUI MVVM framework that provides type-safety for navigation, bindable properties, converters, behaviors, dialogs, data templates, and more in a way that enables developers to code faster, safer, and with less lines.
This wiki will go over all the concepts and support that Shield MVVM brings to developers. If you have any questions, please don't hesitate to ask!
In order to hookup the Navigation, Pages, and Dialogs, a developer must call .UseShieldMVVM() off the MauiAppBuilder at the start of the program. Dialogs also require CommunityToolkit, so developers must also call .UseMauiCommunityToolkit().
See details on the parameters...
With Shield MVVM, View Models are the "central" part to the whole system and are important as a generic parameter to everything else. Whether you are navigating, showing a page, or binding property values, developers will use the provided View Model (or its interfaces) to get everything hooked up.
All XAML pages will need to inherit from ContentPageBase<> where the generic parameter is an IPageViewModelBase (can use PageViewModelBase) the page is tied to. This guarantees type-safety and allows true View Model to View Model navigation.
With the help of the MAUI CommunityToolkit, developers can create dialog ViewModels and show them from a page ViewModel via the Navigation service. These dialogs can have full XAML support with full bindings as if they were a normal page. They can be built just like any other page and you can get a result back from showing them in a similar way to normal pages inside Shield MVVM. All XAML dialogs will need to inherit from DialogPageBase<> where the generic parameter is an IDialogViewModelBase (can use DialogViewModelBase) the dialog is tied to. This guarantees type-safety and allows true View Model to View Model navigation.
By wrapping Microsoft MAUI's navigation, developers can do ViewModel-to-ViewModel navigation. Developers can also pass typed arguments to send data to the next ViewModel and even a typed result back when the user navigates back. The code can await where the navigation took place and the result will come back to that spot in code.
BindingHelper is a class that helps bind View Model properties to control properties via lambda expressions and allows chaining. There are several methods developers can call in order to do various binding, but they are all type-safe.
In MAUI, Bindable Properties are how all the one-way and two-way bindings get hooked up, but they are not type-safe. Shield MVVM wraps them in a type-safe/generic version of BindableProperty to guarantee the developer is binding the correct types. All the "Bind" methods will show up in Intellisense that only apply to the control you are binding and can be chained together. If a developer attempts to bind a different type, the code will not compile. However, a converter can be used inline where Intellisense shows only the possible combinations for the given types.
Converters allow a developer to convert a value from a ViewModel into a more UI friendly version. Shield MVVM comes with type-safe/generic converters to speed up development. The basic implementation allows callbacks to be used, so developers don't have to create new classes every time. Since they are generic, they can be used to support Intellisense in code-behind bindings by making them extension methods. Finally, since these are callbacks, developers can send any number of type-safe parameters into the call in order to do the conversion - developers are not limited to just one parameter of type object.
Similar to converters, Behaviors are also made type-safe/generic. They can be chained with the Bindable Properties in order to add additional functionality. Intellisense will only show you the behaviors that apply to the control you are binding to.
Normally, DataTemplates aren't type safe so there could be issues if the wrong ones are assigned. With Shield MVVM, a generic DataTemplate is available to use in conjunction with a ViewCellBase class that all Cells need to inherit from. Then a BindingHelper method called .ForTemplate can be used to bind an ItemsView to a template/data with type safety - or a DataTemplateSelector. Developers can also use the built in .ForSingleSelection or .ForMultiSelection methods off of SelectableItemsView (e.g. CollectionView) to bind selections in an easier fashion.
Some controls, like labels, don't have the ability to bind clicks out of the box. Shield MVVM exposes a generic bind method to easily wrap any control that allows for gestures. This way, developers can add BindClick to almost any control directly.