Posted Wednesday, November 27, 2013 by Nigel Sampson
In the last few months Windows 8.1 has been released and I’ve had a few questions about Caliburn.Micro and where it stands. Also Caliburn.Micro is releasing an alpha of a new version announced by Rob.
The current version of CM for Windows 8 will work with Windows 8.1 with one issue that I know of. In 8.0 we didn’t have access to the binding infrastructure, especially GetBindingExpression which is how CM determines if a property is already bound. We had to use a pretty nasty hack to get around this, with the changes in 8.1 this nasty hack doesn’t work.
What this means is that if you have an element that could have a convention applied to it by CM but there was already a binding in place CM under 8.0 would skip applying the convention and respect your binding, under 8.1 this won’t happen and CM will happily overwrite the binding with the convention. Not a nasty bug as long as you’re aware of it.
Thankfully in 8.1 we can now do away with our nasty hack and new versions should work well. Speaking of new versions, the current git repository on Codeplex contains the code for the 8.1 version of CM which is still undergoing testing but it doesn’t hurt to take a look at.
From the 8.1 perspective it includes the following:
- Removal of the Callisto dependency in favor of the new Settings Flyout control.
- Removal of the Windows.UI.Interactivity dependency in favor of the new Behaviours SDK from Microsoft.
- Conventions for the new controls such as DatePicker, Flyout, CommandBar and many more.
- Usage of the underlying improvements to the xaml framework for binding including UpdateSourceTrigger.
It’s also available as a pre-release package in Nuget.
Please bear in mind that at the same time CM is making a more to a more portable approach, therefore to keep up with Semantic Versioning this next release will be 2.0 and will definitely contain breaking changes.
Posted Tuesday, October 29, 2013 by Nigel Sampson
Interactive Extensions is a fantastic library from the team that brought us Reactive Extensions, in fact it supports a lot same operations on IEnumerable that Rx brought to IObservable.
The best way to think about it is that it's a library that takes Linq to the next level, there's a nice summary at Interactive Extensions for LINQ to Objects.
However while Ix has been available as a Portable Class Library for a while now it didn't include the appropriate flags for WinRT development. But now it does! Checked in last month to the source was an update to allow it to be used in WinRT, it's not yet published to nuget but I'd highly recommend checking it out.
Posted Monday, October 21, 2013 by Nigel Sampson
Many people including myself have talked about the dangers of async void methods in your Windows 8 application. The fact that exceptions in these methods ultimately caused the application to crash was a big problem, realistically though trying to build a proper application with no async void methods is an exercise in futility. There are ways to mitigate the problem, from replacing the Synchronization Context like we do at Marker Metro, IL Weaving using Fody to plain exception handlers in every async void method.
Thankfully in appears that in Windows 8.1 some of these problems have been alleviated, you’ll notice now that exceptions throw in async void methods will now be passed to the Application.UnhandledException event. There if you set the event arguments Handled property to true you can recover your application from perhaps an unnecessary crash.
protected override void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
e.Handled = true;
All in all I love these little updates to WinRT, here’s hoping we can find some more of them.
Posted Saturday, September 21, 2013 by Nigel Sampson
It's been a busy couple of months which means I haven't posted as much as I'd like. Part of which was because I was preparing to speak at Tech Ed New Zealand.
The talk "Charming Windows 8" is a demo heavy session where I go through the four charms of Windows 8, Search, Share, Print and Settings. Show examples of them all in the built in apps and how to build them all into your own applications. I encourage you to check it out.
It's available to view on Channel 9 under Charming Windows 8, the slides are available to download on Skydrive and the source code for the demo is on GitHub. Enjoy.
Posted Sunday, May 19, 2013 by Nigel Sampson
Often in your view models you’ll need to indicate to the view that some work is happening. In fact I would mandate it, for low powered Windows RT devices. These add to the idea of “perceived performance” in that something on the screen reacts immediately to the users touch and they’re not mashing the screen wondering if it’s working.
I typically make a distinction between Loading and Working. For me Loading is creating, requesting the data that the view presents and would normally be indicated by a Progress Ring in the part of the view this data would be normally shown. Working tends to come after this when the user is acting on the data already loaded, such as Closing an Issue in Hub Bug which I tend to use a Progress Bar across the top of the app (much akin to the Progress Indicator in Windows Phone which tends to get used for both).
There’s a lot of different ways to approach this problem, some people use visual states others use simple Boolean properties on their view models. One thing I found myself doing a lot was starting the working or loading indicator but forgetting to stop it. Admittedly this was pre async / await where you had to bury the stop code in a lambda or callback.
I’ve found using (abusing?) the using statement with disposables to create Loading or Working blocks is a nice way to structure view models so it’s very easy to see how that UI is affected by the view model.
The first thing we need is a little helper class named DisposableAction, this class simply implements IDisposable and takes an Action. When the class is disposed it calls the Action.
public class DisposableAction : IDisposable
private readonly Action action;
public DisposableAction(Action action)
this.action = action;
public void Dispose()
For this example I’ll just a Boolean property IsLoading that’s hypothetically bound to the visibility of a Progress Ring. We’ll create a method calling Loading that first sets IsLoading to true and then returns an DisposableAction that sets it to false when it’s disposed.
protected IDisposable Loading()
IsLoading = true;
return new DisposableAction(() => IsLoading = false);
Now that we have our Loading method we can use it in loading our view model (in this case Caliburn.Micro's OnInitiated). Because Loading returns an IDisposable we can use the using statement to wrap our code and quickly visualise how the Loading.
protected override async void OnInitialize()