×
Namespaces

Variants
Actions
(Difference between revisions)

How to use Cimbalino Windows Phone Toolkit UserInfo - UserExtendedPropertiesService

From Nokia Developer Wiki
Jump to: navigation, search
pavan.pareta (Talk | contribs)
(Pavan.pareta - - Implementing the View)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix metadata)
Line 7: Line 7:
 
|devices= Lumia 800, Lumia 920<!-- Devices tested against - e.g. Nokia Lumia 928, Nokia Asha 501) -->
 
|devices= Lumia 800, Lumia 920<!-- Devices tested against - e.g. Nokia Lumia 928, Nokia Asha 501) -->
 
|sdk= Windows Phone 8.0 SDK, Windows Phone 7.1.1. SDK<!-- SDK(s) built and tested against (e.g. Windows Phone 8.0 SDK) -->
 
|sdk= Windows Phone 8.0 SDK, Windows Phone 7.1.1. SDK<!-- SDK(s) built and tested against (e.g. Windows Phone 8.0 SDK) -->
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->  
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|signing=<!-- Special Signing requirements -->
+
|signing= <!-- Special Signing requirements -->
 
|capabilities= ID_CAP_IDENTITY_USER<!-- Required capabilities for code (e.g. ID_CAP_LOCATION, ID_CAP_NETWORKING) -->
 
|capabilities= ID_CAP_IDENTITY_USER<!-- Required capabilities for code (e.g. ID_CAP_LOCATION, ID_CAP_NETWORKING) -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
|translated-from-title= <!-- Title only - not link -->  
+
|translated-from-title= <!-- Title only - not link -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
|review-by=<!-- After re-review: [[User:username]] -->
+
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-by= <!-- After significant update: [[User:username]]-->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
|creationdate= 20131118<!-- Format YYYYMMDD -->
 
|creationdate= 20131118<!-- Format YYYYMMDD -->
|author= [[User:saramgsilva]]<!-- Enter link [[User:username]] -->
+
|author= [[User:Saramgsilva]]
 
}}
 
}}
  
 
== Introduction ==
 
== Introduction ==
  
The ''Cimbalino Windows Phone Toolkit'' delivers a set of useful and powerful [http://en.wikipedia.org/wiki/Model_View_ViewModel 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. Cimbalino.Phone.Toolkit.UserInfo is a MVVM compatible services for user information access.
+
The ''Cimbalino Windows Phone Toolkit'' delivers a set of useful and powerful [http://en.wikipedia.org/wiki/Model_View_ViewModel 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. Cimbalino.Phone.Toolkit.UserInfo is a MVVM compatible services for user information access.
  
 
[https://github.com/Cimbalino/Cimbalino-Phone-Toolkit/blob/master/src/Cimbalino.Phone.Toolkit.UserInfo%20(WP71)/Services/IUserExtendedPropertiesService.cs IUserExtendedPropertiesService] - Represents an interface for a service capable of obtaining an anonymous identifier for the user of the device.The implementation is [https://github.com/Cimbalino/Cimbalino-Phone-Toolkit/blob/master/src/Cimbalino.Phone.Toolkit.UserInfo%20(WP71)/Services/UserExtendedPropertiesService.cs UserExtendedPropertiesService].
 
[https://github.com/Cimbalino/Cimbalino-Phone-Toolkit/blob/master/src/Cimbalino.Phone.Toolkit.UserInfo%20(WP71)/Services/IUserExtendedPropertiesService.cs IUserExtendedPropertiesService] - Represents an interface for a service capable of obtaining an anonymous identifier for the user of the device.The implementation is [https://github.com/Cimbalino/Cimbalino-Phone-Toolkit/blob/master/src/Cimbalino.Phone.Toolkit.UserInfo%20(WP71)/Services/UserExtendedPropertiesService.cs UserExtendedPropertiesService].

Revision as of 07:28, 26 November 2013

This samples has the goal to show how to use Cimbalino Windows Phone Toolkit UserInfo – UserExtendedPropertiesService.

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): Lumia 800, Lumia 920
CompatibilityPlatform Security
Capabilities: ID_CAP_IDENTITY_USER
Article
Created: saramgsilva (18 Nov 2013)
Last edited: hamishwillee (26 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. Cimbalino.Phone.Toolkit.UserInfo is a MVVM compatible services for user information access.

IUserExtendedPropertiesService - Represents an interface for a service capable of obtaining an anonymous identifier for the user of the device.The implementation is UserExtendedPropertiesService.

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.


Building the example code

The source code for the code example is available here: (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:


Note.pngNote: you must specify the following capabilities in the app manifest: ID_CAP_IDENTITY_USER

Registering the service

Register the service in the ViewModelLocator constructor as shown below

/// <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);
 
SimpleIoc.Default.Register<IUserExtendedPropertiesService, UserExtendedPropertiesService>();
 
SimpleIoc.Default.Register<MainViewModel>();
}
 
public MainViewModel MainViewModel
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
}
 
public static void Cleanup()
{
// TODO Clear the ViewModels
}
}


Implementing the ViewModel

Then we should implement the MainViewModel as following:

  using Cimbalino.Phone.Toolkit.Services;
 
/// <summary>
/// This class contains properties that the main View can data bind to.
/// <para>
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
/// </para>
/// <para>
/// You can also use Blend to data bind with the tool's support.
/// </para>
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class MainViewModel : ViewModelBase
{
/// <summary>
/// The user extended properties service
/// </summary>
private readonly IUserExtendedPropertiesService _userExtendedPropertiesService;
 
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel(IUserExtendedPropertiesService userExtendedPropertiesService)
{
_userExtendedPropertiesService = userExtendedPropertiesService;
}
 
/// <summary>
/// Gets the anonymous user identifier.
/// </summary>
/// <value>
/// The anonymous user identifier.
/// </value>
public string AnonymousUserID
{
get
{
return _userExtendedPropertiesService.AnonymousUserID;
}
}
}


Implementing the View

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: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">
 
<!-- 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="0"
Margin="12,17,0,28">
<TextBlock Margin="12,0"
Style="{StaticResource PhoneTextTitle2Style}"
Text="Cimbalino Sample" />
<TextBlock Margin="9,-7,0,0"
Style="{StaticResource PhoneTextTitle2Style}"
Text="UserExtendedPropertiesService" />
</StackPanel>
 
<!-- ContentPanel - place additional content here -->
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0" >
<TextBlock TextWrapping="Wrap">Anonymous User ID : <Run Text="{Binding AnonymousUserID}"/></TextBlock>
</Grid>
 
</Grid>
 
</phone:PhoneApplicationPage>
130 page views in the last 30 days.