This is the fourth post in this series where we’re configuring a Xamarin.Forms application to use my favourite MVVM framework, Caliburn.Micro. Today’s post will focus on configuring a Universal Windows Application (UWP).
Here’s links to the previous posts:
- Getting Started with Xamarin.Forms and Caliburn.Micro
- Configuring Xamarin.Forms.Droid to use Caliburn.Micro
- Configuring Xamarin.Forms.iOS to use Caliburn.Micro
If you’ve ever built a WPF application, it may seem strange that we’re not going to build XAML pages for our app. Instead, we’re going to leverage the XAML defined in our PCL so that we can reuse as much of the user-interface logic as possible. The pages that we’re adding here act purely as an entry point into our Xamarin.Forms application.
Caliburn provides a base application class that we’re going to extend. In our App.xaml, we’ll change the root element to CaliburnApplication, like so:
Configure IoC Container
Next we’ll add the plumbing logic that we’ve added to the other applications to initialize our platform-specific IoC container. Caliburn.Micro has a customized container for UWP, called WinRTContainer, that contains a few helpful registration methods.
I’ve replaced the default App.xaml.cs with this simplified version:
Eventually, you’ll want to provide additional logic for initialization and suspension specific to UWP, but for now OnLaunched simply launches MainPage as the root window for our Xamarin.Forms app.
The Xamarin.Forms template includes a MainPage that is optimized for Xamarin.Forms, we simply need to load our App from the Singleton defined in Caliburn’s IoC Container.
Build and Run
Finally, before we give our UWP a spin, we need to make a minor change the deployment to the Solution.
- Change the start-up application to XF.CaliburnMicro.UWP (Universal Windows) and set the target platform to Any CPU
- Open the Configuration Manager for the solution
- Specify that the solution should Deploy for Debug configuration
- Specify Local machine as the target Device
- Compile and Run (F5)
You should now see our familiar View / ViewModel from the PCL should be displayed.
Windows 10 Mobile:
We’re now set to handle iOS, Android and Universal Windows Apps using Caliburn.Micro, so that’s all for this series. Follow my Xamarin.Forms label to see more posts in this space.
Until then… Happy Coding.