×
Namespaces

Variants
Actions
Revision as of 01:42, 5 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 samples has the goal to show how to use Cimbalino Windows Phone Toolkit - EmailComposeService, MarketplaceReviewService and ShareLinkService.

SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
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 (05 Nov 2013)

Introduction

Cimbalino Windows Phone Toolkit is a set of useful and powerful items that will help you build your Silverlight applications for Windows Phone. The Toolkit is divided in projects which deliver different features. The base project (Cimbalino.Phone.Toolkit) contains base MVVM services, some very useful converters, helper classes and extension methods, and the bindable Application Bar behaviour.

  • IMarketplaceReviewService is an interface (Cimbalino toolkit - source code here) Represents an interface for a service capable of showing the marketplace review screen for an application and the implementation for this interface will be MarketplaceReviewService.
  • IShareLinkService is an interface (Cimbalino toolkit- source code here) Represents an interface for a service capable of sharing links over the social networks configured on the device. The implementation is ShareLinkService.

Building Sample

This packages is available in Nuget Package Manager (for both targets) and can be installed, for more details see: How to install Cimbalino Windows Phone Toolkit packages.

The sample for this article uses MVVM Light for help in MVVM pattern implementation, for more details see:

Let's start!

We should register each service in ViewModelLocator, as following:

/// <summary>
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
/// </summary>
public class ViewModelLocator
{
/// <summary>
/// Initializes a new instance of the ViewModelLocator class.
/// </summary>
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
 
if (!SimpleIoc.Default.IsRegistered<IMarketplaceReviewService>())
{
SimpleIoc.Default.Register<IMarketplaceReviewService, MarketplaceReviewService>();
}
 
if (!SimpleIoc.Default.IsRegistered<IShareLinkService>())
{
SimpleIoc.Default.Register<IShareLinkService, ShareLinkService>();
}
 
if (!SimpleIoc.Default.IsRegistered<IEmailComposeService>())
{
SimpleIoc.Default.Register<IEmailComposeService, EmailComposeService>();
}
 
SimpleIoc.Default.Register<MainViewModel>();
}
 
public MainViewModel MainViewModel
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}
 
public static void Cleanup()
{
// TODO Clear the ViewModels
}
}

Then we should implement the MainViewModel as following:

/// <summary>
/// This class contains properties that the main View can data bind to.
/// </summary>
public class MainViewModel : ViewModelBase
{
/// <summary>
/// The email compose service.
/// </summary>
private readonly IEmailComposeService _emailComposeService;
 
/// <summary>
/// The marketplace review service.
/// </summary>
private readonly IMarketplaceReviewService _marketplaceReviewService;
 
/// <summary>
/// The share link service.
/// </summary>
private readonly IShareLinkService _shareLinkService;
 
/// <summary>
/// The public application url.
/// </summary>
private readonly string _appUrl;
 
/// <summary>
/// Initializes a new instance of the <see cref="MainViewModel"/> class.
/// </summary>
/// <param name="emailComposeService">
/// The email Compose Service.
/// </param>
/// <param name="marketplaceReviewService">
/// The marketplace review service
/// </param>
/// <param name="shareLinkService">
/// The share Link Service.
/// </param>
public MainViewModel(
IEmailComposeService emailComposeService,
IMarketplaceReviewService marketplaceReviewService,
IShareLinkService shareLinkService)
{
_emailComposeService = emailComposeService;
_marketplaceReviewService = marketplaceReviewService;
_shareLinkService = shareLinkService;
 
RateCommand = new RelayCommand(this.Rate);
SendFeedbackCommand = new RelayCommand(this.SendFeedback);
ShareToMailCommand = new RelayCommand(this.ShareToMail);
ShareSocialNetworkCommand = new RelayCommand(this.ShareSocialNetwork);
_appUrl = string.Concat("http://windowsphone.com/s?appid=8df00038-1b7a-406b-b33f-37a78b17348c");
}
 
/// <summary>
/// Gets the rate command.
/// </summary>
public ICommand RateCommand { get; private set; }
 
/// <summary>
/// Gets the send feedback command.
/// </summary>
public ICommand SendFeedbackCommand { get; private set; }
 
/// <summary>
/// Gets the share social network command.
/// </summary>
public ICommand ShareSocialNetworkCommand { get; private set; }
 
/// <summary>
/// Gets the share to e-mail command.
/// </summary>
public ICommand ShareToMailCommand { get; private set; }
 
/// <summary>
/// The rate.
/// </summary>
private void Rate()
{
_marketplaceReviewService.Show();
}
 
/// <summary>
/// The send feedback.
/// </summary>
private void SendFeedback()
{
const string To = "saramgsilva@gmail.com";
const string Subject = "My Feedback";
var body = "This the body";
_emailComposeService.Show(To, Subject, body);
}
 
/// <summary>
/// The share social network.
/// </summary>
private void ShareSocialNetwork()
{
const string Message = "This application is amazing, should try it! See in";
_shareLinkService.Show("Cimbalino Toolkit Sample", Message, new Uri(_appUrl, UriKind.Absolute));
}
 
/// <summary>
/// The share to mail.
/// </summary>
private void ShareToMail()
{
const string Subject = "Cimbalino Toolkit Sample";
var body = string.Concat("This application is amazing, you should try it! See in", _appUrl);
_emailComposeService.Show(Subject, body);
}
}

for connect view model with the page we should add the ViewModelLocator instance in App.xaml

<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />

and add the binding in main page like:

 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:cimbalino="clr-namespace:Cimbalino.Phone.Toolkit.Behaviors;assembly=Cimbalino.Phone.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
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">
 
<!-- LayoutRoot is the root grid where all page content is placed -->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
 
<!-- TitlePanel contains the name of the application and page title -->
<StackPanel x:Name="TitlePanel"
Grid.Row="1"
Margin="0,5,12,396">
<TextBlock Margin="12,0"
Style="{StaticResource PhoneTextTitle2Style}"
Text="Cimbalino Toolkit Sample" />
</StackPanel>
<TextBlock Grid.RowSpan="2"
Margin="12,50,-3,487"
Style="{StaticResource PhoneTextTitle3Style}"
TextWrapping="Wrap">
This samples has the goal to show how to use Cimbalino Toolkit - EmailComposeService, MarketplaceReviewService and ShareLinkService.
</TextBlock>
<!-- ContentPanel - place additional content here -->
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0" />
<i:Interaction.Behaviors>
<cimbalino:ApplicationBarBehavior>
<cimbalino:ApplicationBarIconButton Command="{Binding RateCommand,
Mode=OneTime}"
IconUri="/Images/appbar.rate.png"
Text="Rate it" />
<cimbalino:ApplicationBarIconButton Command="{Binding SendFeedbackCommand,
Mode=OneTime}"
IconUri="/Images/appbar.reply.email.png"
Text="Feedback" />
<cimbalino:ApplicationBarIconButton Command="{Binding ShareToMailCommand,
Mode=OneTime}"
IconUri="/Images/appbar.email.png"
Text="Email" />
<cimbalino:ApplicationBarIconButton Command="{Binding ShareSocialNetworkCommand,
Mode=OneTime}"
IconUri="/Images/appbar.share.png"
Text="Share it" />
</cimbalino:ApplicationBarBehavior>
</i:Interaction.Behaviors>
</Grid>
 
</phone:PhoneApplicationPage>

The MainPage result will be:

MainPage result

Related samples

217 page views in the last 30 days.