×
Namespaces

Variants
Actions
(Difference between revisions)

Como usar Cimballino Windows Phone Toolkit PhoneDialer - PhoneCallService

From Nokia Developer Wiki
Jump to: navigation, search
saramgsilva (Talk | contribs)
(Saramgsilva -)
 
saramgsilva (Talk | contribs)
(Saramgsilva -)
Line 1: Line 1:
[[Category:Draft]][[Category:Windows Phone 8]][[Category:Windows Phone 7.5]][[Category:How To]][[Category:MVVM Light Toolkit]][[Category:Cimbalino Windows Phone Toolkit]]
+
[[Category:Windows Phone 8]][[Category:Windows Phone 7.5]][[Category:How To]][[Category:MVVM Light Toolkit]][[Category:Cimbalino Windows Phone Toolkit]]
 
+
 
{{Abstract| Este artigo mostra como usar o Cimbalino Windows Phone Toolkit PhoneDialer - PhoneCallService. }}  
 
{{Abstract| Este artigo mostra como usar o Cimbalino Windows Phone Toolkit PhoneDialer - PhoneCallService. }}  
  

Revision as of 14:28, 27 November 2013

Este artigo mostra como usar o Cimbalino Windows Phone Toolkit PhoneDialer - PhoneCallService.

WP Metro Icon MobilePhone.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata

Testado com
SDK: Windows Phone 8.0 SDK, Windows Phone 7.1.1. SDK
Aparelho(s): Lumia 920, Lumia 800

Compatibilidade
Platform Security
Capabilities: ID_CAP_PHONEDIALER

Artigo
Tradução:
Por saramgsilva
Última alteração feita por saramgsilva em 27 Nov 2013

Contents

Introdução

Cimbalino Windows Phone Toolkit é um conjunto de itens uteis e poderosos para ajudar na implementação de aplicações Windows Phone. Projeto base do toolkit contendo serviços para implementação do padrão de MVVM, conversores, classes auxiliares, métodos de extensões;

Cimbalino.Phone.Toolkit.PhoneDialer - Projeto do toolkit contendo serviços para implementação do padrão de MVVM com acesso ao telefone.

Note.pngNote: é preciso definir a capacidade ID_CAP_PHONEDIALER no ficheiro manifest.

Contruindo o exemplo

O código fonte pode ser obtido em (github).

Os pacotes estão disponíveis em Nuget Package Manager (para ambos os "targets") e podem ser instalados, para mais detalhes consultar: Como instalar os pacotes Cimbalino Windows Phone Toolkit. O exemplo deste artigo usa MVVM Light para ajudar na implementação do padrão MVVM, para mais detalhes consultar:

Registando os serviços

Devemos começar por registar cada serviço no ViewModelLocator, como podemos ver de seguida:

    /// <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();
}
}

Implementando a ViewModel

Em seguinda devemos implementar o MainViewModel, como podemos ver de seguida:

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

Implementando a View

A MainPage.xaml será algo do género:

<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>
71 page views in the last 30 days.
×