Most applications, Metro App or not, allows user to view or modify application settings. In WinRT development especially with XAML/C# , it’s not straight forward as we have to create our own settings flyout as well as handle everything from creating SettingsCommand to closing our settings area. Callisto, a control toolkit for Windows 8 XAML applications created by Tim Heuer, does help by providing a way to create SettingsFlyout and SettingsManagement.
You can get Caliburn.Micro using NuGet (Callisto is also installed if your app have not installed it already).
I won’t get into detail about how to have your app implement MVVM pattern with Caliburn.Micro. Here are some links that should help you get started.
- Caliburn.Micro for WinRT: Getting Started by Mikael Koskinen
- WinRT and Caliburn.Micro by Terry Marshall
In this post, I will add About option into the Settings charm. I start by adding AboutViewModel and AboutView into the project. Caliburn.Micro utilizes convention over configuration pattern, so I can just create the view and view model, and let Caliburn.Micro links them together without explicitly specify it.
The code is pretty simple.
After we have View and View Model ready, we can just register the setting service and About command with AboutViewModel.
Let’s see the app in action:
That’s it. You don’t need to worry about creating a popup wrapping user controls and handle their life cycle. Implementing settings charm won’t pollute your nice and clean MVVM WinRT app anymore 🙂 .
Note: if you want to customize the background header of the setting dialog, you can do something like this.