How to use Cimbalino Windows Phone Toolkit Media Library – FMRadioService

This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Media Library – FMRadioService.

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.

Cimbalino.Phone.Toolkit.MediaLibrary is a MVVM compatible services for media library access

Note: you must specify the following capabilities in the app manifest: ID_CAP_MEDIALIB

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:

   using Cimbalino.Phone.Toolkit.Services;
    using GalaSoft.MvvmLight;
    using GalaSoft.MvvmLight.Ioc;
    using Microsoft.Practices.ServiceLocation;

    /// <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<IFMRadioService>())
            {
                SimpleIoc.Default.Register<IFMRadioService, FMRadioService>();
            }
            SimpleIoc.Default.Register<MainViewModel>();
        }

        /// <summary>
        /// Gets the main view model.
        /// </summary>
        /// <value>
        /// The main view model.
        /// </value>
        public MainViewModel MainViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        public static void Cleanup()
        {
            // TODO Clear the ViewModels
            var viewModelLocator = (ViewModelLocator)App.Current.Resources["Locator"];
            viewModelLocator.MainViewModel.Cleanup();
        }
    }

Then we should implement the MainViewModel as following:

 using System.Windows;
    using System.Windows.Input;
    using System.Windows.Threading;

    using Cimbalino.Phone.Toolkit.Services;

    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight;

    using Microsoft.Devices.Radio;

    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// The FM radio service
        /// </summary>
        private readonly IFMRadioService _fmRadioService;

        /// <summary>
        /// The frequency
        /// </summary>
        private double _frequency;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IFMRadioService fmRadioService)
        {
            _fmRadioService = fmRadioService;
            PropertyChanged += MainViewModel_PropertyChanged;
            Frequency = 91.7;
            _fmRadioService.CurrentRegion = RadioRegion.Europe;
            _fmRadioService.PowerOff();
            StopCommand= new RelayCommand(Stop);
            PlayCommand = new RelayCommand(Play);
        }

        /// <summary>
        /// Plays this instance.
        /// </summary>
        private void Play()
        {
          _fmRadioService.PowerOn();
        }

        /// <summary>
        /// Stops this instance.
        /// </summary>
        private void Stop()
        {
         _fmRadioService.PowerOff();   
        }

        /// <summary>
        /// Gets or sets the frequency.
        /// </summary>
        /// <value>
        /// The frequency.
        /// </value>
        public double Frequency
        {
            get
            {
                return this._frequency;
            }
            set
            {
                Set("Frequency", ref _frequency, value);
            }
        }

        /// <summary>
        /// Gets the play command.
        /// </summary>
        /// <value>
        /// The play command.
        /// </value>
        public ICommand PlayCommand { get; private set; }

        /// <summary>
        /// Gets the stop command.
        /// </summary>
        /// <value>
        /// The stop command.
        /// </value>
        public ICommand StopCommand { get; private set; }

        /// <summary>
        /// Handles the PropertyChanged event of the MainViewModel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
        private void MainViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Frequency")
            {
                _fmRadioService.Frequency = Frequency;
            }
        }
    }

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:converters="clr-namespace:Cimbalino.Phone.Toolkit.Converters;assembly=Cimbalino.Phone.Toolkit"
                            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="FMRadioService" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <TextBlock TextWrapping="Wrap">This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Media Library - FMRadioService</TextBlock>

            <TextBlock Margin="0,90,0,-90" Text="Frequency:" />
            <TextBox Margin="0,122,0,451" Text="{Binding Frequency, Mode=TwoWay}" />
            <Button Margin="0,219,0,293"
                    Command="{Binding PlayCommand}"
                    Content="Play" />
            <Button Margin="0,351,0,161"
                    Command="{Binding StopCommand}"
                    Content="Stop" />
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

How to use Cimbalino Windows Phone Toolkit Media Library – MediaLibraryService

This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Media Library – MediaLibraryService.

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.

Cimbalino.Phone.Toolkit.MediaLibrary is a MVVM compatible services for media library access

Note: you must specify the following capabilities in the app manifest: ID_CAP_MEDIALIB_PHOTO

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:

using Cimbalino.Phone.Toolkit.Services;
    using GalaSoft.MvvmLight;
    using GalaSoft.MvvmLight.Ioc;
    using Microsoft.Practices.ServiceLocation;

    /// <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<INavigationService>())
            {
                SimpleIoc.Default.Register<INavigationService, NavigationService>();
            }

            if (!SimpleIoc.Default.IsRegistered<IMediaLibraryService>())
            {
                SimpleIoc.Default.Register<IMediaLibraryService, MediaLibraryService>();
            }
            if (!SimpleIoc.Default.IsRegistered<ICameraCaptureService>())
            {
                SimpleIoc.Default.Register<ICameraCaptureService, CameraCaptureService>();
            }
            SimpleIoc.Default.Register<MainViewModel>();
            SimpleIoc.Default.Register<AlbunsViewModel>();
            SimpleIoc.Default.Register<PicturesViewModel>();
        }

        /// <summary>
        /// Gets the main view model.
        /// </summary>
        /// <value>
        /// The main view model.
        /// </value>
        public MainViewModel MainViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        /// <summary>
        /// Gets the albuns view model.
        /// </summary>
        /// <value>
        /// The albuns view model.
        /// </value>
        public AlbunsViewModel AlbunsViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<AlbunsViewModel>();
            }
        }

        /// <summary>
        /// Gets the pictures view model.
        /// </summary>
        /// <value>
        /// The pictures view model.
        /// </value>
        public PicturesViewModel PicturesViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<PicturesViewModel>();
            }
        }

        /// <summary>
        /// Cleanups.
        /// </summary>
        public static void Cleanup()
        {
            // TODO Clear the ViewModels
            var viewModelLocator = (ViewModelLocator)App.Current.Resources["Locator"];
            viewModelLocator.MainViewModel.Cleanup();
        }
    }

Then we should implement the MainViewModel as following:

using System;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Threading;

    using Cimbalino.Phone.Toolkit.Services;

    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight;

    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// The navigation service
        /// </summary>
        private readonly INavigationService _navigationService;

        /// <summary>
        /// The media library service
        /// </summary>
        private readonly IMediaLibraryService _mediaLibraryService;

        /// <summary>
        /// The camera capture service
        /// </summary>
        private readonly ICameraCaptureService _cameraCaptureService;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        /// <param name="navigationService">The navigation service.</param>
        /// <param name="mediaLibraryService">The media library service.</param>
        /// <param name="cameraCaptureService">The camera capture service.</param>
        public MainViewModel(INavigationService navigationService, IMediaLibraryService mediaLibraryService, ICameraCaptureService cameraCaptureService)
        {
            _navigationService = navigationService;
            _mediaLibraryService = mediaLibraryService;
            _cameraCaptureService = cameraCaptureService;
            ShowAlbunsCommand =new RelayCommand(ShowAlbuns);
            ShowPicturesCommand = new RelayCommand(ShowPictures);
            SavePictureCommand = new RelayCommand(SavePicture);
        }

        /// <summary>
        /// Saves the picture.
        /// </summary>
        private void SavePicture()
        {
            _cameraCaptureService.Show(CameraCapetureResult);
        }

        /// <summary>
        /// Shows the pictures.
        /// </summary>
        private void ShowPictures()
        {
            _navigationService.NavigateTo(new Uri("/PicturesPage.xaml", UriKind.Relative));
        }

        /// <summary>
        /// Shows the albuns.
        /// </summary>
        private void ShowAlbuns()
        {
            _navigationService.NavigateTo(new Uri("/AlbunsPage.xaml", UriKind.Relative));
        }

        /// <summary>
        /// Gets the show albuns command.
        /// </summary>
        /// <value>
        /// The show albuns.
        /// </value>
        public ICommand ShowAlbunsCommand { get; private set; }
        /// <summary>
        /// Gets the show pictures command.
        /// </summary>
        /// <value>
        /// The show pictures command.
        /// </value>
        public ICommand ShowPicturesCommand { get; private set; }

        /// <summary>
        /// Gets the sava picture command.
        /// </summary>
        /// <value>
        /// The sava picture command.
        /// </value>
        public ICommand SavePictureCommand { get; private set; }

        /// <summary>
        /// Cameras the capeture result.
        /// </summary>
        /// <param name="photoResult">The photo result.</param>
        private async void CameraCapetureResult(Microsoft.Phone.Tasks.PhotoResult photoResult)
        {
            if (photoResult.ChosenPhoto != null)
            {
                _mediaLibraryService.SavePicture("CimbalinoPicture",photoResult.ChosenPhoto);
            }
        }
    }

and PicturesViewModel as following:

using Cimbalino.Phone.Toolkit.Services;

    using GalaSoft.MvvmLight;

    using Microsoft.Xna.Framework.Media;

    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// </summary>
    public class PicturesViewModel:ViewModelBase
    {
        /// <summary>
        /// The media library service
        /// </summary>
        private readonly IMediaLibraryService _mediaLibraryService;

        /// <summary>
        /// Initializes a new instance of the <see cref="PicturesViewModel" /> class.
        /// </summary>
        /// <param name="mediaLibraryService">The media library service.</param>
        public PicturesViewModel(IMediaLibraryService mediaLibraryService)
        {
            _mediaLibraryService = mediaLibraryService;
        }

        /// <summary>
        /// Gets the pictures.
        /// </summary>
        /// <value>
        /// The pictures.
        /// </value>
        public PictureCollection Pictures
        { 
            get
            {
                return _mediaLibraryService.Pictures;
            } 
        }
    }

and AlbunsViewModel as following:

   using Cimbalino.Phone.Toolkit.Services;

    using Microsoft.Xna.Framework.Media;

    public class AlbunsViewModel
    {
         /// <summary>
        /// The media library service
        /// </summary>
        private readonly IMediaLibraryService _mediaLibraryService;

        /// <summary>
        /// Initializes a new instance of the <see cref="PicturesViewModel" /> class.
        /// </summary>
        /// <param name="mediaLibraryService">The media library service.</param>
        public AlbunsViewModel(IMediaLibraryService mediaLibraryService)
        {
            _mediaLibraryService = mediaLibraryService;
        }

        /// <summary>
        /// Gets a lbuns.
        /// </summary>
        /// <value>
        /// Albuns.
        /// </value>
        public AlbumCollection Albuns 
        { 
            get
            {
                return _mediaLibraryService.Albums;
            } 
        }
    }

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: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="MediaLibraryService" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <TextBlock TextWrapping="Wrap">This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Media Library - MediaLibraryService</TextBlock>

            <Button Margin="0,209,0,303"
                    Command="{Binding SavePictureCommand}"
                    Content="Save Picture" />
            <Button Margin="2.985,332.896,-2.985,179.104"
                    Command="{Binding ShowPicturesCommand}"
                    Content="Show Pictures" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto" >
                <Button.RenderTransform>
                    <CompositeTransform SkewX="1.914" TranslateX="-2.205"/>
                </Button.RenderTransform>
            </Button>

            <Button Margin="0,447,0,65"
                    Command="{Binding ShowAlbunsCommand}"
                    Content="Show Albuns" />
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

and PicturesPage.xaml can be the following:

<phone:PhoneApplicationPage x:Class="CimbalinoSample.PicturesPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP8"
                            xmlns:converters="clr-namespace:CimbalinoSample.Converters"
                            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 PicturesViewModel,
                                                  Source={StaticResource Locator}}"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            Orientation="Portrait"
                            SupportedOrientations="Portrait"
                            shell:SystemTray.IsVisible="True"
                            mc:Ignorable="d">
    <phone:PhoneApplicationPage.Resources>
        <converters:MedialibraryConverter x:Key="medialibraryConverter" />
    </phone:PhoneApplicationPage.Resources>
    <!--  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 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="Pictures" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <ListBox ItemsSource="{Binding Pictures}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <Image Height="100"
                                   Source="{Binding Converter={StaticResource medialibraryConverter}}"
                                   Stretch="Uniform" />
                            <TextBlock>
                                Name:<Run Text="{Binding Name}" />
                            </TextBlock>
                            <TextBlock>
                                Width:<Run Text="{Binding Width}" />
                            </TextBlock>
                            <TextBlock>
                                Height:<Run Text="{Binding Height}" />
                            </TextBlock>
                            <TextBlock>
                                Date:<Run Text="{Binding Date}" />
                            </TextBlock>
                            <TextBlock>
                                Album:<Run Text="{Binding Album}" />
                                <LineBreak />
                            </TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

Which MediaLibraryConverter is:

/// <summary>
    /// The media library converter class
    /// </summary>
    public class MedialibraryConverter : IValueConverter
    {
        /// <summary>
        /// Converts the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="culture">The culture.</param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
           var image = (Microsoft.Xna.Framework.Media.Picture) value;
            return PictureDecoder.DecodeJpeg(image.GetImage());
        }

        /// <summary>
        /// Converts the back.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="targetType">Type of the target.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="culture">The culture.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

and AlbunsPage.xaml can be the following:

<phone:PhoneApplicationPage x:Class="CimbalinoSample.AlbunsPage"
                            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"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            Orientation="Portrait"
                            DataContext="{Binding AlbunsViewModel,
                                                  Source={StaticResource Locator}}"
                            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 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="Albuns" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0" >
            <ListBox ItemsSource="{Binding Albuns}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock>
                                Name :<Run Text="{Binding Name}" />
                            </TextBlock>
                            <TextBlock>
                                Artist: <Run Text="{Binding Artist}" />
                            </TextBlock>
                            <TextBlock>
                                Duration :<Run Text="{Binding Duration}" />
                            </TextBlock>
                            <TextBlock>
                                Genre :<Run Text="{Binding Genre}" />
                            </TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

How to use Cimbalino Windows Phone Toolkit Media Library – ScreenshotService

This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Media Library – ScreenshotService.

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.

Cimbalino.Phone.Toolkit.MediaLibrary is a MVVM compatible services for media library access

  • IScreenshotService Represents an interface for a service capable of taking screenshots. The implementation is ScreenshotService.

Note: you must specify the following capabilities in the app manifest: ID_CAP_MEDIALIB_PHOTO

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:

using Cimbalino.Phone.Toolkit.Services;
    using GalaSoft.MvvmLight;
    using GalaSoft.MvvmLight.Ioc;
    using Microsoft.Practices.ServiceLocation;

    /// <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<IScreenshotService>())
            {
                SimpleIoc.Default.Register<IScreenshotService, ScreenshotService>();
            }
            SimpleIoc.Default.Register<MainViewModel>();
        }

        /// <summary>
        /// Gets the main view model.
        /// </summary>
        /// <value>
        /// The main view model.
        /// </value>
        public MainViewModel MainViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        public static void Cleanup()
        {
            // TODO Clear the ViewModels
            var viewModelLocator = (ViewModelLocator)App.Current.Resources["Locator"];
            viewModelLocator.MainViewModel.Cleanup();
        }
    }

Then we should implement the MainViewModel as following:

 using System.Windows;
    using System.Windows.Input;
    using System.Windows.Threading;

    using Cimbalino.Phone.Toolkit.Services;

    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight;
    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// The screenshot service
        /// </summary>
        private readonly IScreenshotService _screenshotService;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IScreenshotService screenshotService)
        {
            _screenshotService = screenshotService;
            TakeScreenshotCommand = new RelayCommand(TakeScreenshot);
        }

        /// <summary>
        /// Gets the take screenshot command.
        /// </summary>
        /// <value>
        /// The take screenshot command.
        /// </value>
        public ICommand TakeScreenshotCommand { get; private set; }

        /// <summary>
        /// Calls to.
        /// </summary>
        private void TakeScreenshot()
        {
            _screenshotService.TakeScreenshot("CimbalinoScreenshot");
        }
    }

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: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="ScreenshotService" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <TextBlock TextWrapping="Wrap">This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Media Library - ScreenshotService</TextBlock>

            <Button Margin="0,219,0,293"
                    Command="{Binding TakeScreenshotCommand}"
                    Content="Take Screenshot" />
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

How to use Cimballino Windows Phone Toolkit PhoneDialer – PhoneCallService

This samples has the goal to show how to use Cimbalino Windows Phone Toolkit PhoneDialer – PhoneCallService.

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.

Cimbalino.Phone.Toolkit.PhoneDialer is a MVVM compatible services for phone dialer access

Note: you must specify the following capabilities in the app manifest: ID_CAP_PHONEDIALER

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<IPhoneCallService>())
            {
                SimpleIoc.Default.Register<IPhoneCallService, PhoneCallService>();
            }
            SimpleIoc.Default.Register<MainViewModel>();
        }

        /// <summary>
        /// Gets the main view model.
        /// </summary>
        /// <value>
        /// The main view model.
        /// </value>
        public MainViewModel MainViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        public static void Cleanup()
        {
            // TODO Clear the ViewModels
            var viewModelLocator = (ViewModelLocator)App.Current.Resources["Locator"];
            viewModelLocator.MainViewModel.Cleanup();
        }
    }

Then we should implement the MainViewModel as following:

using System.Windows;
    using System.Windows.Input;
    using System.Windows.Threading;

    using Cimbalino.Phone.Toolkit.Services;

    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight;
    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// The phone call service
        /// </summary>
        private readonly IPhoneCallService _phoneCallService;

        /// <summary>
        /// The number
        /// </summary>
        private string _number;

        /// <summary>
        /// The name
        /// </summary>
        private string _name;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IPhoneCallService phoneCallService)
        {
            _phoneCallService = phoneCallService;
            CallCommand =new RelayCommand(CallTo);
        }

        /// <summary>
        /// Gets or sets the number.
        /// </summary>
        /// <value>
        /// The number.
        /// </value>
        public string Number
        {
            get
            {
                return _number;
            }
            set
            {
                Set("Number", ref _number, value);
            }
        }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                Set("Name", ref _name, value);
            }
        }

        /// <summary>
        /// Gets the call command.
        /// </summary>
        /// <value>
        /// The call command.
        /// </value>
        public ICommand CallCommand { get; private set; }

        /// <summary>
        /// Calls to.
        /// </summary>
        private void CallTo()
        {
            _phoneCallService.Show(Number, Name);
        }
    }

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: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 PhoneTextTitle1Style}"
                       Text="PhoneDailer" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <TextBlock TextWrapping="Wrap">
                Name:
            </TextBlock>
            <TextBlock Margin="0,100,0,-100" TextWrapping="Wrap">
                Number:
            </TextBlock>
            <TextBox Text="{Binding Name,Mode=TwoWay}" Margin="-10,20,10,496"/>
            <TextBox Text="{Binding Number,Mode=TwoWay}" Margin="-10,122,10,399"/>
            <Button Margin="0,219,0,293"
                    Command="{Binding CallCommand}"
                    Content="Call" />
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

[PT] 43ª Reunião Presencial da Comunidade NetPonto em Lisboa

No dia 23-11-2013 será realizada a 43ª Reunião Presencial da Comunidade NetPonto em Lisboa. Para participar, efectue o registo de acordo com as instruções abaixo.

Agenda

09:45  – Recepção dos participantes
10:00  – Deep dive into Windows Azure Mobile ServicesRicardo Costa
A apresentação tenta cobrir todos os serviços disponibilizados pela plataforma Azure Mobile.Desde data-storage até server-side code, passando por push notifications e custom API.

Serão também abordados os temas de source-control, scheduler, logging e scaling.

11:30  – Intervalo
12:00  – The power of templating…. with NVelocityNuno Cancelo
Desde os inicio dos tempos existem padrões de desenho ainda que não tivessem um nome atribuído e com o aparecimento da Internet para o mero utilizador, tornou-se evidente para o programador a importância da utilização de padrões e separar as responsabilidades dos módulos das suas aplicações.O padrão mais conhecido por entre as aplicações é o MVC ou criar um conjuntos de boas práticas e separar a aplicação em três componentes: O Modelo, o Controlador e a Vista. E é com este padrão que dispara o potencial dos “templates engines”, ao permitir alcançar os objectivos lançados pela nossa imaginação e propósito da aplicação, como por exemplo gerar Templates para:

  • páginas web
  • emails
  • geração de código

Na sessão vamos falar do NVelocity, um template engine com grande potencial que permite realizar o limite da nossa mente.

13:30  – Painel de Discussão e Sorteio de Prémios
Nota: Ao final da reunião, escolhemos um restaurante próximo e fazemos um almoço em grupo para continuar o convívio e aproximar as pessoas. A participação é opcional.

Registo / Inscrição

Para participar, basta efectuar a inscrição através do site:
http://netponto-lisboa-novembro-2013.eventbrite.com/A entrada é gratuita.

Qualquer questão / esclarecimento, entre em contacto connosco.


Local

Microsoft Portugal – Auditório
Rua do Fogo de Santelmo, Lote 2.07.02
1990-110 Lisboa
Portugal

Clique para ampliar o mapa.

How to use Cimbalino Windows Phone Toolkit Location

This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Location – LocationService.

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.

Cimbalino.Phone.Toolkit.Location is a MVVM compatible services for location access.

Note: you must specify the following capabilities in the app manifest: ID_CAP_LOCATION

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<ILocationService>())
            {
                SimpleIoc.Default.Register<ILocationService, LocationService>();
            }
            SimpleIoc.Default.Register<MainViewModel>();
        }

        /// <summary>
        /// Gets the main view model.
        /// </summary>
        /// <value>
        /// The main view model.
        /// </value>
        public MainViewModel MainViewModel
        {
            get
            {
                return ServiceLocator.Current.GetInstance<MainViewModel>();
            }
        }

        public static void Cleanup()
        {
            // TODO Clear the ViewModels
            var viewModelLocator = (ViewModelLocator)App.Current.Resources["Locator"];
            viewModelLocator.MainViewModel.Cleanup();
        }
    }

Then we should implement the MainViewModel as following:

using System.Windows;
    using System.Windows.Input;
    using System.Windows.Threading;

    using Cimbalino.Phone.Toolkit.Services;

    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight;
    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// The location service
        /// </summary>
        private readonly ILocationService _locationService;

        private bool _isLocationEnable;

        /// <summary>
        /// Define if is start enable
        /// </summary>
        private bool _isStartEnable;

        /// <summary>
        /// Define if is stop enable
        /// </summary>
        private bool _isStopEnable;

        /// <summary>
        /// The latitude
        /// </summary>
        private double _latitude;

        /// <summary>
        /// The logitude
        /// </summary>
        private double _longitude;

        /// <summary>
        /// The status
        /// </summary>
        private LocationServiceStatus _status;
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(ILocationService locationService)
        {
            IsStartEnable = true;
            IsLocationEnable = true;
            IsStopEnable = false;
            _locationService = locationService;
            _locationService.ReportInterval = 5;
            _locationService.PositionChanged += LocationService_PositionChanged;
            _locationService.StatusChanged += LocationService_StatusChanged;
            StartCommand =new RelayCommand(Start);
            StopCommand =new RelayCommand(Stop);
            LocationCommand = new RelayCommand(GetLocation);
        }

        /// <summary>
        /// Gets or sets a value indicating whether [is location enable].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [is location enable]; otherwise, <c>false</c>.
        /// </value>
        public bool IsLocationEnable
        {
            get
            {
                return this._isLocationEnable;
            }
            set
            {
                Set("IsLocationEnable", ref _isLocationEnable, value);
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [is start enable].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [is start enable]; otherwise, <c>false</c>.
        /// </value>
        public bool IsStartEnable
        {
            get
            {
                return this._isStartEnable;
            }
            set
            {
                Set("IsStartEnable", ref _isStartEnable, value);
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [is stop enable].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [is stop enable]; otherwise, <c>false</c>.
        /// </value>
        public bool IsStopEnable
        {
            get
            {
                return this._isStopEnable;
            }
            set
            {
                Set("IsStopEnable", ref _isStopEnable, value);
            }
        }

        /// <summary>
        /// Gets or sets the latitude.
        /// </summary>
        /// <value>
        /// The latitude.
        /// </value>
        public double Latitude
        {
            get
            {
                return _latitude;
            }
            set
            {
                Set("Latitude", ref _latitude, value);
            }
        }

        /// <summary>
        /// Gets or sets the location command.
        /// </summary>
        /// <value>
        /// The get location command.
        /// </value>
        public ICommand LocationCommand { get; private set; }

        /// <summary>
        /// Gets or sets the longitude.
        /// </summary>
        /// <value>
        /// The logitude.
        /// </value>
        public double Longitude
        {
            get
            {
                return this._longitude;
            }
            set
            {
                Set("Longitude", ref _longitude, value);
            }
        }

        /// <summary>
        /// Gets or sets the start command.
        /// </summary>
        /// <value>
        /// The start command.
        /// </value>
        public ICommand StartCommand { get; private set; }

        /// <summary>
        /// Gets or sets the status.
        /// </summary>
        /// <value>
        /// The status.
        /// </value>
        public LocationServiceStatus Status
        {
            get
            {
                return _status;
            }
            set
            {
                Set("Status", ref _status, value);
            }
        }
        /// <summary>
        /// Gets or sets the stop command.
        /// </summary>
        /// <value>
        /// The stop command.
        /// </value>
        public ICommand StopCommand { get; private set; }
        /// <summary>
        /// Unregisters this instance from the Messenger class.
        /// <para>To cleanup additional resources, override this method, clean
        /// up and then call base.Cleanup().</para>
        /// </summary>
        public override void Cleanup()
        {
            base.Cleanup();
            _locationService.PositionChanged -= LocationService_PositionChanged;
            _locationService.StatusChanged -= LocationService_StatusChanged;
        }

        /// <summary>
        /// Gets the location.
        /// </summary>
        private async void GetLocation()
        {
            var result = await _locationService.GetPositionAsync();
            Longitude = result.Longitude;
            Latitude = result.Latitude;
        }

        /// <summary>
        /// Handles the PositionChanged event of the LocationService control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LocationServicePositionChangedEventArgs"/> instance containing the event data.</param>
        private void LocationService_PositionChanged(object sender, LocationServicePositionChangedEventArgs e)
        {
            Deployment.Current.Dispatcher.BeginInvoke(delegate
                {
                    Latitude = e.Position.Latitude;
                    Longitude = e.Position.Longitude;
                });
        }

        /// <summary>
        /// Handles the StatusChanged event of the _locationService control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LocationServiceStatusChangedEventArgs"/> instance containing the event data.</param>
        private void LocationService_StatusChanged(object sender, LocationServiceStatusChangedEventArgs e)
        {
            Deployment.Current.Dispatcher.BeginInvoke(delegate { Status = e.Status; });
        }

        /// <summary>
        /// Starts the location service.
        /// </summary>
        private void Start()
        {
            IsStartEnable = false;
            IsStopEnable = true;
            IsLocationEnable = false;
            _locationService.Start();
        }

        /// <summary>
        /// Stops the location service.
        /// </summary>
        private void Stop()
        {
            IsLocationEnable = true;
            IsStartEnable = true;
            IsStopEnable = false;
            _locationService.Stop();
        }
    }

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: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 PhoneTextTitle1Style}"
                       Text="Location" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <TextBlock TextWrapping="Wrap">
                Latitude:<Run Text="{Binding Latitude}" />
            </TextBlock>
            <TextBlock Margin="0,51,0,-51" TextWrapping="Wrap">
                Logitude:<Run Text="{Binding Longitude}" />
            </TextBlock>
            <TextBlock Margin="0,102,0,-102" TextWrapping="Wrap">
                Status:<Run Text="{Binding Status}" />
            </TextBlock>
            <Button Margin="0,298,0,214"
                    IsEnabled="{Binding IsStartEnable}"
                    Command="{Binding StartCommand}"
                    Content="Start" />
            <Button Height="76"
                    IsEnabled="{Binding IsStopEnable}"
                    Margin="0,0,0,138"
                    VerticalAlignment="Bottom"
                    Command="{Binding StopCommand}"
                    Content="Stop" />
            <Button Margin="0,219,0,293"
                    IsEnabled="{Binding IsLocationEnable}"
                    Command="{Binding LocationCommand}"
                    Content="Get location" />
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

How to use Cimbalino Windows Phone Toolkit UserInfo – UserExtendedPropertiesService

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

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.

Cimbalino.Phone.Toolkit.UserInfo – MVVM compatible services for user information access

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

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);

            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
        }
    }

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;
            }
        }
    }

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: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>

How to use Cimbalino Windows Phone Toolkit Camera – CameraCaptureService

This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Camera – CameraCaptureService.

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.

Cimbalino.Phone.Toolkit.Camera is a MVVM compatible services for camera access.

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<ICameraCaptureService>())
            {
                SimpleIoc.Default.Register<ICameraCaptureService, CameraCaptureService>();
            }

            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 camera capture service
        /// </summary>
        private readonly ICameraCaptureService _cameraCaptureService;

        /// <summary>
        /// The image
        /// </summary>
        private ImageSource _image;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(ICameraCaptureService cameraCaptureService)
        {
            _cameraCaptureService = cameraCaptureService;
            CameraCaptureCommand = new RelayCommand(CameraCapture);
        }

        /// <summary>
        /// Gets the camera capture command.
        /// </summary>
        /// <value>
        /// The camera capture command.
        /// </value>
        public ICommand CameraCaptureCommand { get; private set; }

        /// <summary>
        /// Gets or sets the image.
        /// </summary>
        /// <value>
        /// The image.
        /// </value>
        public ImageSource Image
        {
            get
            {
                return _image;
            }
            set
            {
                Set("Image", ref _image, value);
            }
        }

        /// <summary>
        /// Cameras the capture.
        /// </summary>
        private void CameraCapture()
        {
            Image = null;
            _cameraCaptureService.Show(CameraCapetureResult);
        }

        /// <summary>
        /// Cameras the capeture result.
        /// </summary>
        /// <param name="photoResult">The photo result.</param>
        private async void CameraCapetureResult(Microsoft.Phone.Tasks.PhotoResult photoResult)
        {
            if(photoResult.ChosenPhoto!=null)
            {
                var bitmapImage = new BitmapImage();
                bitmapImage.SetSource(photoResult.ChosenPhoto);
                Image = bitmapImage;
            }
        }
    }

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:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    DataContext="{Binding MainViewModel, Source={StaticResource Locator}}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--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 Text="Cimbalino Sample" Style="{StaticResource PhoneTextTitle2Style}" Margin="12,0"/>
            <TextBlock Text="CameraCaptureService and PhotoCameraService" 
                       TextWrapping="Wrap"
                       Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle2Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Image Source="{Binding Image}" Stretch="Uniform" Margin="0,242,0,0" />
            <Button Content="Camera Capture" Command="{Binding CameraCaptureCommand}" Height="237" VerticalAlignment="Top"/>

        </Grid>
    </Grid>
</phone:PhoneApplicationPage>

How to use Cimbalino Windows Phone Toolkit Device Info – DeviceExtendedPropertiesService

This samples has the goal to show how to use Cimbalino Windows Phone Toolkit Device Info – DeviceExtendedPropertiesService.

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.

Cimbalino.Phone.Toolkit.DeviceInfo – MVVM compatible services for device information access

Note: you must specify the following capabilities in the app manifest: ID_CAP_IDENTITY_DEVICE

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);
            Cimbalino.Phone.Toolkit.Services.DeviceExtendedPropertiesService
            if (!SimpleIoc.Default.IsRegistered<IDeviceExtendedPropertiesService>())
            {
                SimpleIoc.Default.Register<IDeviceExtendedPropertiesService, DeviceExtendedPropertiesService>();
            }

            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 device extended properties service
        /// </summary>
        private readonly IDeviceExtendedPropertiesService _deviceExtendedPropertiesService;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDeviceExtendedPropertiesService deviceExtendedPropertiesService)
        {
            _deviceExtendedPropertiesService = deviceExtendedPropertiesService;
        }

        /// <summary>
        /// Gets the device unique identifier.
        /// </summary>
        /// <value>
        /// The device unique identifier.
        /// </value>
        public string DeviceUniqueID
        {
            get
            {
                return Convert.ToBase64String(_deviceExtendedPropertiesService.DeviceUniqueId);
            }
        }

        /// <summary>
        /// Gets the application current memory usage.
        /// </summary>
        /// <value>
        /// The application current memory usage.
        /// </value>
        public long ApplicationCurrentMemoryUsage
        {
            get
            {
                return _deviceExtendedPropertiesService.GetDeviceProperty<long>("ApplicationCurrentMemoryUsage");
            }
        }

        /// <summary>
        /// Gets the application peak memory usage.
        /// </summary>
        /// <value>
        /// The application peak memory usage.
        /// </value>
        public long ApplicationPeakMemoryUsage
        {
            get
            {
                return _deviceExtendedPropertiesService.GetDeviceProperty<long>("ApplicationPeakMemoryUsage");
            }
        }

        /// <summary>
        /// Gets the device firmware version.
        /// </summary>
        /// <value>
        /// The device firmware version.
        /// </value>
        public string DeviceFirmwareVersion
        {
            get
            {
                return _deviceExtendedPropertiesService.GetDeviceProperty<string>("DeviceFirmwareVersion");
            }
        }

        /// <summary>
        /// Gets the device hardware version.
        /// </summary>
        /// <value>
        /// The device hardware version.
        /// </value>
        public string DeviceHardwareVersion
        {
            get
            {
                return _deviceExtendedPropertiesService.GetDeviceProperty<string>("DeviceHardwareVersion");
            }
        }

        /// <summary>
        /// Gets the device manufacturer.
        /// </summary>
        /// <value>
        /// The device manufacturer.
        /// </value>
        public string DeviceManufacturer
        {
            get
            {
                return _deviceExtendedPropertiesService.GetDeviceProperty<string>("DeviceManufacturer");
            }
        }

        /// <summary>
        /// Gets the name of the device.
        /// </summary>
        /// <value>
        /// The name of the device.
        /// </value>
        public string DeviceName
        {
            get
            {
                return _deviceExtendedPropertiesService.GetDeviceProperty<string>("DeviceName");
            }
        }

        /// <summary>
        /// Gets the device total memory.
        /// </summary>
        /// <value>
        /// The device total memory.
        /// </value>
        public long DeviceTotalMemory
        {
            get
            {
                return _deviceExtendedPropertiesService.GetDeviceProperty<long>("DeviceTotalMemory");
            }
        }

        /// <summary>
        /// Gets the name of the original mobile operator.
        /// </summary>
        /// <value>
        /// The name of the original mobile operator.
        /// </value>
        public string OriginalMobileOperatorName
        {
            get
            {
                return _deviceExtendedPropertiesService.GetDeviceProperty<string>("OriginalMobileOperatorName");
            }
        }
    }

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: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"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            Orientation="Portrait"
                             DataContext="{Binding MainViewModel, 
                                                    Source={StaticResource Locator}}"
                            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" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <TextBlock TextWrapping="Wrap">
                Device Unique ID: <LineBreak/><Run Text="{Binding DeviceUniqueID}" />
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,50,0,0">
                Application Current Memory Usage: <LineBreak/><Run Text="{Binding ApplicationCurrentMemoryUsage}" />
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,100,0,0">
                Application Peak Memory Usage: <LineBreak/><Run Text="{Binding ApplicationPeakMemoryUsage}" />
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,150,0,0">
               Device Firmware Version: <LineBreak/><Run Text="{Binding DeviceFirmwareVersion}" />
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,200,0,0">
                Device Hardware Version: <LineBreak/><Run Text="{Binding DeviceHardwareVersion}" />
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,250,0,0">
                Device Manufacturer: <LineBreak/><Run Text="{Binding DeviceManufacturer}" />
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,300,0,0">
                Device Name: <LineBreak/><Run Text="{Binding DeviceName}" />
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,350,0,0">
                Device Total Memory: <LineBreak/><Run Text="{Binding DeviceTotalMemory}" />
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,400,0,0">
               Original Mobile Operator Name: <LineBreak/><Run Text="{Binding OriginalMobileOperatorName}" />
            </TextBlock>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

 

How to use Cimbalino Windows Phone Toolkit – MessageBoxService

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

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.

  • IMessageBoxService – Represents an interface for a service capable of showing message boxes. The implementation is MessageBoxService.

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:

 using Cimbalino.Phone.Toolkit.Services;

    /// <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<IMessageBoxService>())
            {
                SimpleIoc.Default.Register<IMessageBoxService, MessageBoxService>();
            }

            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:

 

 using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Input;

    using Cimbalino.Phone.Toolkit.Services;

    using GalaSoft.MvvmLight.Command;

    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// The message box service.
        /// </summary>
        private readonly IMessageBoxService _messageBoxService;

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IMessageBoxService messageBoxService)
        {
            _messageBoxService = messageBoxService;
            ShowMessageBoxCommand = new RelayCommand(ShowMessageBox);
        }

        /// <summary>
        /// Shows the message box.
        /// </summary>
        private void ShowMessageBox()
        {
            _messageBoxService.Show("I am a message box", "Cimbalino sample", MessageBoxButton.OK);
        }

        /// <summary>
        /// Gets the show message box command.
        /// </summary>
        /// <value>
        /// The show message box command.
        /// </value>
        public ICommand ShowMessageBoxCommand { get; private set; }
    }

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: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"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            Orientation="Portrait"
                            DataContext="{Binding MainViewModel, 
                                                  Source={StaticResource Locator}}"
                            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="MessageBoxService" />
        </StackPanel>

        <!--  ContentPanel - place additional content here  -->
        <Grid x:Name="ContentPanel"
              Grid.Row="1"
              Margin="12,0,12,0">
            <Button Command="{Binding ShowMessageBoxCommand}" Content="Show message box" />
        </Grid>

    </Grid>

</phone:PhoneApplicationPage>