This code example shows how to read information in the application manifest file (AppManifest.xml) using ApplicationManifestService from the Cimbalino Windows Phone Toolkit .



Introduction



The Cimbalino Windows Phone Toolkit delivers a set of useful and powerful MVVM-compatible tools and services to help developers build Silverlight applications for Windows Phone.



The Toolkit is divided into projects that deliver various features, ranging from base MVVM services and helpers, through to code for background agents and for accessing a media library, location services and so on. The base project (Cimbalino.Phone.Toolkit ) contains base MVVM services, some very useful converters, helper classes and extension methods.



Cimbalino.Phone.Toolkit.Background (contains the ApplicationManifestService) is MVVM compatible services for background agents.



The Cimbalino Toolkit's Application Manifest service is used to read information from the application manifest. This file includes, in particular, information that it can be useful to display in an app's about page, like the app version, author, product ID and so on. The kit provides both the IApplicationManifestService interface and its implementation ApplicationManifestService required to register the service in MVVM Light (note that MVVM and the MVVM Light Toolkit are not "preconditions" to use this service).



A screenshot of the example app is shown below:





Application manifest file information displayed in the app.

Building the Example Code



The source code for the code example is available here: ApplicationManifestService (Include sample for WP8.0 and WP8.1SL).



To build the source code you will also need the MVVM Light Toolkit and the Cimbalino Windows Phone Toolkit . Their packages are available in the NuGet Package Manager .



The Sample



Registering the service



We should register each service in ViewModelLocator, as in the following:



public class ViewModelLocator { public ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); if (!SimpleIoc.Default.IsRegistered<IApplicationManifestService>()) { SimpleIoc.Default.Register<IApplicationManifestService, ApplicationManifestService>(); } SimpleIoc.Default.Register<MainViewModel>(); } public MainViewModel MainViewModel { get { return ServiceLocator.Current.GetInstance<MainViewModel>(); } } public static void Cleanup() { } }



Implementing the ViewModel



Then we should implement the MainViewModel as in the following:



public class MainViewModel : ViewModelBase { private readonly string _appUrl; private readonly ApplicationManifest _applicationManifest; public MainViewModel(IApplicationManifestService applicationManifestService) { _applicationManifest = applicationManifestService.GetApplicationManifest(); _appUrl = string .Concat( "http://windowsphone.com/s?appid= " , _applicationManifest.App.ProductId); } public string Title { get { return _applicationManifest.App.Title; } } public string Author { get { return _applicationManifest.App.Author; } } public string Version { get { return _applicationManifest.App.Version; } } public string Description { get { return _applicationManifest.App.Description; } } public string ProductID { get { return _applicationManifest.App.ProductId; } } public string Publisher { get { return _applicationManifest.App.Publisher; } } public IList Capabilities { get { return _applicationManifest.App.Capabilities.ToList(); } } }



Implementing the View



Add the binding to the main page as shown:



DataContext= "{Binding MainViewModel, Source={StaticResource Locator}}"



The MainPage.xaml can be the following:



< phone:PhoneApplicationPage x:Class = "CimbalinoSample.MainPage" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml " xmlns:d = "http://schemas.microsoft.com/expression/blend/2008 " xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006 " xmlns:phone = "clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell = "clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" DataContext ="{Binding MainViewModel, Source ={StaticResource Locator}}" FontFamily = "{StaticResource PhoneFontFamilyNormal}" FontSize = "{StaticResource PhoneFontSizeNormal}" Foreground = "{StaticResource PhoneForegroundBrush}" Orientation = "Portrait" SupportedOrientations = "Portrait" shell:SystemTray.IsVisible = "True" mc:Ignorable = "d" > < Grid x:Name = "LayoutRoot" Background = "Transparent" > < Grid.RowDefinitions > < RowDefinition Height = "Auto" /> < RowDefinition Height = "*" /> </ Grid.RowDefinitions > < StackPanel x:Name = "TitlePanel" Grid.Row = "0" Margin = "12,17,0,28" > < TextBlock Margin = "12,0" Style = "{StaticResource PhoneTextTitle2Style}" Text = "Cimbalino Sample" /> </ StackPanel > < Grid x:Name = "ContentPanel" Grid.Row = "1" Margin = "12,0,12,0" > < TextBlock TextWrapping = "Wrap" VerticalAlignment = "Top" Height = "50" > Title: < Run Text = "{Binding Title}" /> </ TextBlock > < TextBlock TextWrapping = "Wrap" VerticalAlignment = "Top" Margin = "0,50,0,0" > Author: < Run Text = "{Binding Author}" /> </ TextBlock > < TextBlock TextWrapping = "Wrap" VerticalAlignment = "Top" Margin = "0,100,0,0" > Version: < Run Text = "{Binding Version}" /> </ TextBlock > < TextBlock TextWrapping = "Wrap" VerticalAlignment = "Top" Margin = "0,150,0,0" > Description: < Run Text = "{Binding Description}" /> </ TextBlock > < TextBlock TextWrapping = "Wrap" VerticalAlignment = "Top" Margin = "0,300,0,0" > ProductID: < Run Text = "{Binding ProductID}" /> </ TextBlock > < TextBlock TextWrapping = "Wrap" VerticalAlignment = "Top" Margin = "0,350,0,0" > Publisher: < Run Text = "{Binding Publisher}" /> </ TextBlock > < TextBlock TextWrapping = "Wrap" Text = "Capabilities:" VerticalAlignment = "Top" Margin = "0,400,0,0" /> < ListBox DisplayMemberPath = "Name" Margin = "0,450,0,0" ItemsSource = "{Binding Capabilities}" /> </ Grid > </ Grid > </ phone:PhoneApplicationPage >



Source Code Files

ViewModelLocator.cs has the ViewModelLocator class that helps to bind the view model with the view.

MainViewModel.cs has the MainViewModel class that represents the view model for the main page.

MainPage.xaml and MainPage.xaml.cs represent the main page.

See Also