-
-
Notifications
You must be signed in to change notification settings - Fork 144
Home
Stylet is a minimal, but powerful, MVVM framework inspired by Caliburn.Micro. Its intention is to cut down on the complexity and magic even further, to allow people (coworkers) unfamiliar with any MVVM framework to get up to speed more quickly.
It also provides features not available in Caliburn.Micro, including its own IoC container, easy ViewModel validation, and even an MVVM-compatible MessageBox.
The low LOC count and very comprehensive test suite makes it an attractive option for projects where using and validating/verifying SOUP comes with a high overhead, which its modular toolkit-inspired architecture means it's easy to use just the bits you like, or replace the bits you don't.
A brief feature list is shown below. Follow the links on the right to learn more.
The classic MVVM structure, where a view knows how to instantiate its ViewModel, and ViewModels typically don't communicate directly, is known as View-first. However, reversing this pattern - instantiating the ViewModels yourself and having the Views automatically attached - provides many advantages, allowing you to compose your ViewModels in a way which should feel very familiar. This ViewModel-first approach is the only one supported by Stylet.
The ICommand interface used by WPF is powerful, but clunky when used in an MVVM architecture. It doesn't seem right that actions to be taken by your ViewModel in response to things like button clicks should be represented as properties, rather than methods. A simple <Button Command="{s:Action DoSomething}"/>
will cause DoSomething()
on your ViewModel to be called every time the button is clicked. Additionally, if you have a bool property called CanDoSomething
, that will be observed and used to tell whether the button should be enabled or disabled.
Actions also work with events, allowing you to do things like <Button MouseEnter="{s:Action DoSomethingElse}"/>
.
The Screen class provides many things which make it an attractive base class for your ViewModels: PropertyChanged notifications, validation, and the ability to be notified when it's shown/hidden/closed, and the ability to control if and when it can be closed.
Stylet's Event Aggregator is very similar to Caliburn.Micro's, and allows subscribers to receive messages from publishes without either having knowledge of, or retaining, the other. This is particularly useful for messaging between ViewModels, although it has plenty of other uses.
With a ViewModel-first approach, you display windows and dialogs by referencing the ViewModel to display, and the View gets attached automatically. The WindowManager allows this to be done with ease.
An MVVM-compatible MessageBox implementation is also provided, so you don't have to roll your own.
Validation in MVVM is traditionally a bit of a pain: it requires a fair amount of boilerplate in each ViewModel that requires validation, and resources on how to do this well are sparse.
Stylet comes with a framework for taking your favourite validation library (e.g. FluentValidation) and handles running validations and reporting the results to the View.
Stylet comes with its own lightweight and extremely fast (but still powerful) IoC container, although it's easy to use another one if you'd prefer.
Stylet is distributed under the MIT license, which allows you to modify Stylet, and include it in commercial projects, without attributation (the only restriction being that you must include a copy of the license). I'm open to re-licensing it on a case-by-case basis if you require this.
- Introduction
- Quick Start
- Bootstrapper
- ViewModel First
- Actions
- The WindowManager
- MessageBox
- The EventAggregator
- PropertyChangedBase
- Execute: Dispatching to the UI Thread
- Screens and Conductors
- BindableCollection
- Validation using ValidatingModelBase
- StyletIoC
- The ViewManager
- Listening to INotifyPropertyChanged
- Design Mode Support
- Logging
- Misc