Alternatively you can right-click on both Projects from the Solution Explorer and select âManage NuGet PackagesâŚâ, then click the Online pane and search for Caliburn.Micro. You must install CM into both .Core and .UI projects!
Â
Once Caliburn.Micro finishes installing it should open up a web page with instructions to finish the configuration.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using Caliburn.Micro;
using Microsoft.Phone.Controls;
using RealWorldStocks.Client.UI.ViewModels.Home;
namespace RealWorldStocks.Client.UI.Framework
{
public class AppBootstrapper : PhoneBootstrapper
{
PhoneContainer _container;
protected override void Configure()
{
_container = new PhoneContainer(RootFrame);
_container.RegisterPhoneServices();
_container.Singleton<HomeViewModel>();
}
protected override void OnUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached)
{
Debugger.Break();
e.Handled = true;
}
else
{
MessageBox.Show("An unexpected error occured, sorry about the troubles.", "Oops...", MessageBoxButton.OK);
e.Handled = true;
}
base.OnUnhandledException(sender, e);
}
protected override object GetInstance(Type service, string key)
{
return _container.GetInstance(service, key);
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return _container.GetAllInstances(service);
}
protected override void BuildUp(object instance)
{
_container.BuildUp(instance);
}
}
}
<Application xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Framework="clr-namespace:RealWorldStocks.Client.UI.Framework"
x:Class="RealWorldStocks.Client.UI.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Constants.xaml"/>
<ResourceDictionary Source="Assets/Styles.xaml"/>
<ResourceDictionary Source="Assets/Converters.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Framework:AppBootstrapper x:Key="bootstrapper" />
</ResourceDictionary>
</Application.Resources>
</Application>
Â
At the time of this writing there appears to be a bug in the NuGet package which thinks my project is a Silverlight project (instead of Windows Phone).
If the NuGet package created a ShellViewModel.cs in your project, then you will need to take the following steps:
The final pieces of our infrastructure include the following:
I have a set of IValueConverters that I have used on all of my Windows Phone projects. They can be viewed from the CodePlex source code.
Assets are a set of ResourceDictionaries that contain the resources used throughout the application. They can be viewed from the CodePlex source code.
Defines variables like âAppNameâ so it can be used on pages <TextBlock Text=â{StaticResource AppName}â />
Defines the set of converters used in our project
Defines a set of reusable styles
Â
ViewModels define the logic for all of our views. They take advantage of XAMLâs great binding mechanisms and Caliburnâs ActionMessages to control how our views behave. Later in the series we will deep dive into Views and ViewModels.
To get started, make sure you have a ViewModels folder, then right-click and select New ItemâŚ, add a Class file called **HomeViewModel.cs **
public class HomeViewModel : Screen
{
public HomeViewModel()
{
DisplayName = "Home";
}
}
Views are your .xaml Pages and UserControls. Later in the series we will deep dive into Views and ViewModels.
To get started, make sure you have a Views folder, then right-click and select New ItemâŚ, add a Windows Phone Portrait Page called HomeView.xaml
Lastly, you need to update the WMAppManifest to tell it what page should load when the app is launched.
Open WMAppManifest.xml and set the NavigationPage to your primary page
<DefaultTask Name="_default" NavigationPage="Views/HomeView.xaml" />
Â
Now weâre getting somewhere. We have the majority of our application infrastructure in place and have our first View and ViewModel. If you press F5 now it should launch right into the HomeView!
If the app exits immediately after launching check the following:
Leave a Comment