×
Namespaces

Variants
Actions
Revision as of 19:31, 23 November 2013 by saramgsilva (Talk | contribs)

How to add marketplace review using the Cimbalino Windows Phone Toolkit

From Nokia Developer Wiki
Jump to: navigation, search

This code example shows how to add marketplace review to your app using MarketplaceReviewService from the Cimbalino Windows Phone Toolkit.

SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code Example
Installation file: MarketplaceReviewService (github)
Tested with
SDK: Windows Phone 8.0 SDK, Windows Phone 7.1.1 SDK
Devices(s): Nokia Lumia 800, 920
CompatibilityArticle
Created: saramgsilva (05 Nov 2013)
Last edited: saramgsilva (23 Nov 2013)

Contents

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 in projects which deliver different features, ranging from base MVVM services and helpers, through to code for background agents, and for accessing media library, location services etc. The base project (Cimbalino.Phone.Toolkit) contains base MVVM services, some very useful converters, helper classes and extension methods.

The Cimbalino Toolkit's "Market Place Review" service is used to launch the marketplace review screen for an app, making it easier for users to rate and review. The kit provides both the IMarketplaceReviewService interface and its implementation MarketplaceReviewService required to register the service in MVVM Light (note that MVVM and the MVVM Light Toolkit are not "preconditions" to use this service).

This article explains how to use the service in an MVVM Light app. Developers should first read How to use MVVM Light Toolkit for Windows Phone for a general overview of MVVM Light and how to use services.

A screenshot of the example app, with the icon used to launch marketplace review, is shown below.

Marketplacereview.png

Building the example code

The source code for the code example is available here: MarketplaceReviewService (github).

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. For more details see:


The sample is built using MVVM Light and the article does not go into great detail about the plumbing/infrastructure provided by the toolkit. For more information see:

Registering the service

Register the service in the ViewModelLocator constructor as shown below (ViewModelLocator.cs).

  1.         public ViewModelLocator()
  2.         {
  3.             ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
  4.  
  5.             if (!SimpleIoc.Default.IsRegistered<IMarketplaceReviewService>())
  6.             {
  7.                 SimpleIoc.Default.Register<IMarketplaceReviewService, MarketplaceReviewService>();
  8.             }
  9.  
  10.             SimpleIoc.Default.Register<MainViewModel>();
  11.         }

In the next section we see that the MainViewModel constructor takes a IMarketplaceReviewService parameter. When ViewModelLocator creates the view model it recognises that the parameter is registered, creates an instance of the MarketplaceReviewService and passes it to MainViewModel.


Implementing the ViewModel

Implement the MainViewModel as shown below. The highlighted sections show the MainViewModel constructor taking the IMarketplaceReviewService parameter and assigning it to the private variable, and later on the variable being used to show the market place review prompt.

  1.     /// This class contains properties that the main View can data bind to.
  2.     public class MainViewModel : ViewModelBase
  3.     {
  4.         /// The marketplace review service.
  5.         private readonly IMarketplaceReviewService _marketplaceReviewService;
  6.  
  7.         /// The public application url.
  8.         private readonly string _appUrl;
  9.  
  10.         /// The marketplace review service
  11.         public MainViewModel(IMarketplaceReviewService marketplaceReviewService)
  12.         {
  13.             _marketplaceReviewService = marketplaceReviewService;
  14.  
  15.             RateCommand = new RelayCommand(Rate);
  16.         }
  17.  
  18.         /// Gets the rate command.
  19.         public ICommand RateCommand { get; private set; }
  20.  
  21.         /// The rate.
  22.         private void Rate()
  23.         {
  24.             _marketplaceReviewService.Show();
  25.         }
  26.     }

Implementing the view

The rest of the app is "plumbing" to hook up the MainViewModel to the View and send commands back to the invoke the service. How to use MVVM Light Toolkit for Windows Phone explains most of what is going on, but for completeness the MainPage.xaml is as shown below:

  1. <phone:PhoneApplicationPage x:Class="CimbalinoSample.MainPage"
  2.                             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.                             xmlns:cimbalino="clr-namespace:Cimbalino.Phone.Toolkit.Behaviors;assembly=Cimbalino.Phone.Toolkit"
  5.                             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6.                             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
  7.                             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8.                             xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
  9.                             xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
  10.                             DataContext="{Binding MainViewModel,
  11.                                                   Source={StaticResource Locator}}"
  12.                             FontFamily="{StaticResource PhoneFontFamilyNormal}"
  13.                             FontSize="{StaticResource PhoneFontSizeNormal}"
  14.                             Foreground="{StaticResource PhoneForegroundBrush}"
  15.                             Orientation="Portrait"
  16.                             SupportedOrientations="Portrait"
  17.                             shell:SystemTray.IsVisible="True"
  18.                             mc:Ignorable="d">
  19.  
  20.     <!--  LayoutRoot is the root grid where all page content is placed  -->
  21.     <Grid x:Name="LayoutRoot" Background="Transparent">
  22.         <Grid.RowDefinitions>
  23.             <RowDefinition Height="Auto" />
  24.             <RowDefinition Height="*" />
  25.         </Grid.RowDefinitions>
  26.  
  27.         <!--  TitlePanel contains the name of the application and page title  -->
  28.         <StackPanel x:Name="TitlePanel"
  29.                     Grid.Row="1"
  30.                     Margin="0,5,12,396">
  31.             <TextBlock Margin="12,0"
  32.                        Style="{StaticResource PhoneTextTitle2Style}"
  33.                        Text="Cimbalino Toolkit Sample" />
  34.         </StackPanel>
  35.         <TextBlock Grid.RowSpan="2"
  36.                    Margin="12,50,-3,487"
  37.                    Style="{StaticResource PhoneTextTitle3Style}"
  38.                    TextWrapping="Wrap">
  39.             This samples has the goal to show how to use Cimbalino Toolkit -  MarketplaceReviewService
  40.         </TextBlock>
  41.         <!--  ContentPanel - place additional content here  -->
  42.         <Grid x:Name="ContentPanel"
  43.               Grid.Row="1"
  44.               Margin="12,0,12,0" />
  45.         <i:Interaction.Behaviors>
  46.             <cimbalino:ApplicationBarBehavior>
  47.                 <cimbalino:ApplicationBarIconButton Command="{Binding RateCommand,
  48.                                                                       Mode=OneTime}"
  49.                                                     IconUri="/Images/appbar.rate.png"
  50.                                                     Text="Rate it" />
  51.             </cimbalino:ApplicationBarBehavior>
  52.         </i:Interaction.Behaviors>
  53.     </Grid>
  54.  
  55. </phone:PhoneApplicationPage>

The first highlighted lines show binding the MainViewModel as a DataContext for the page.

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

The second highlighted section sets the application bar "Rate it" icon and binds to RateCommand in the MainViewModel.

        <i:Interaction.Behaviors>
<cimbalino:ApplicationBarBehavior>
<cimbalino:ApplicationBarIconButton Command="{Binding RateCommand,
Mode=OneTime}"

IconUri="/Images/appbar.rate.png"
Text="Rate it" />
</cimbalino:ApplicationBarBehavior>
</i:Interaction.Behaviors>

Related samples

Source Code

Source code is available here

153 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×