×
Namespaces

Variants
Actions
(Difference between revisions)

Como usar Cimbalino Windows Phone Toolkit - ApplicationManifestService

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix categories. Move screenshot into introduction)
hamishwillee (Talk | contribs)
m (Hamishwillee - Tidy some of the example code. Did not add the highlighting I have i)
 
(4 intermediate revisions by 2 users not shown)
Line 12: Line 12:
 
|language= Lang-Portuguese
 
|language= Lang-Portuguese
 
|translated-by= [[User:saramgsilva]]<!-- [[User:XXXX]] -->
 
|translated-by= [[User:saramgsilva]]<!-- [[User:XXXX]] -->
|translated-from-title= How to use Cimbalino Windows Phone Toolkit - ApplicationManifestService<!-- Title only - not link -->
+
|translated-from-title= How to use Cimbalino Windows Phone Toolkit - ApplicationManifestService
 
|translated-from-id= <!-- Id of translated revision -->
 
|translated-from-id= <!-- Id of translated revision -->
 
|review-by= <!-- After re-review: [[User:username]] -->
 
|review-by= <!-- After re-review: [[User:username]] -->
Line 34: Line 34:
  
 
== Contruindo o exemplo ==
 
== Contruindo o exemplo ==
 +
 +
O código fonte pode ser obtido em [https://github.com/saramgsilva/CimbalinoToolkitSamples/tree/master/How%20to%20use%20Cimbalino%20Windows%20Phone%20Toolkit%20Background%20-%20ApplicationManifestService Exemplo ApplicationManifestService] (github).
  
 
Os pacotes estão disponíveis em [http://docs.nuget.org/docs/start-here/managing-nuget-packages-using-the-dialog Nuget Package Manager] (para ambos os "targets") e podem ser instalados, para mais detalhes consultar: [[Como instalar os pacotes Cimbalino Windows Phone Toolkit]].
 
Os pacotes estão disponíveis em [http://docs.nuget.org/docs/start-here/managing-nuget-packages-using-the-dialog Nuget Package Manager] (para ambos os "targets") e podem ser instalados, para mais detalhes consultar: [[Como instalar os pacotes Cimbalino Windows Phone Toolkit]].
Line 41: Line 43:
 
*[[Como usar MVVM Light Toolkit para Windows Phone]]
 
*[[Como usar MVVM Light Toolkit para Windows Phone]]
  
Vamos começar!
+
== Registando serviços ==
  
 
Devemos começar por registar cada serviço no ViewModelLocator, como podemos ver de seguida:  
 
Devemos começar por registar cada serviço no ViewModelLocator, como podemos ver de seguida:  
  
 
<code csharp>
 
<code csharp>
/// <summary>
 
 
     /// This class contains static references to all the view models in the
 
     /// This class contains static references to all the view models in the
 
     /// application and provides an entry point for the bindings.
 
     /// application and provides an entry point for the bindings.
    /// </summary>
 
 
     public class ViewModelLocator
 
     public class ViewModelLocator
 
     {
 
     {
        /// <summary>
 
 
         /// Initializes a new instance of the ViewModelLocator class.
 
         /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
 
 
         public ViewModelLocator()
 
         public ViewModelLocator()
 
         {
 
         {
Line 80: Line 78:
 
     }
 
     }
 
</code>
 
</code>
 +
 +
== Implementando a ViewModel ==
  
 
Em seguinda devemos implementar o MainViewModel, como podemos ver de seguida:  
 
Em seguinda devemos implementar o MainViewModel, como podemos ver de seguida:  
  
 
<code csharp>
 
<code csharp>
/// <summary>
 
 
     /// This class contains properties that the main View can data bind to.
 
     /// This class contains properties that the main View can data bind to.
    /// </summary>
 
 
     public class MainViewModel : ViewModelBase
 
     public class MainViewModel : ViewModelBase
 
     {
 
     {
        /// <summary>
 
 
         /// The public application url.
 
         /// The public application url.
        /// </summary>
 
 
         private readonly string _appUrl;
 
         private readonly string _appUrl;
  
        /// <summary>
 
 
         /// The application manifest.
 
         /// The application manifest.
        /// </summary>
 
 
         private readonly ApplicationManifest _applicationManifest;
 
         private readonly ApplicationManifest _applicationManifest;
  
        /// <summary>
+
         /// Initializes a new instance of the application Manifest Service.
         /// Initializes a new instance of the <see cref="MainViewModel"/> class.
+
        /// </summary>
+
        /// <param name="emailComposeService">
+
        /// The email Compose Service.
+
        /// </param>
+
        /// <param name="applicationManifestService">
+
        /// The application Manifest Service.
+
        /// </param>
+
        /// <param name="marketplaceReviewService">
+
        /// The marketplace review service
+
        /// </param>
+
        /// <param name="shareLinkService">
+
        /// The share Link Service.
+
        /// </param>
+
 
         public MainViewModel(IApplicationManifestService applicationManifestService)
 
         public MainViewModel(IApplicationManifestService applicationManifestService)
 
         {
 
         {
Line 120: Line 100:
 
         }
 
         }
  
        /// <summary>
 
 
         /// Gets the title.
 
         /// Gets the title.
        /// </summary>
 
 
         public string Title
 
         public string Title
 
         {
 
         {
Line 131: Line 109:
 
         }
 
         }
  
        /// <summary>
 
 
         /// Gets the author.
 
         /// Gets the author.
        /// </summary>
 
 
         public string Author
 
         public string Author
 
         {
 
         {
Line 142: Line 118:
 
         }
 
         }
  
        /// <summary>
 
 
         /// Gets the version.
 
         /// Gets the version.
        /// </summary>
 
 
         public string Version
 
         public string Version
 
         {
 
         {
Line 153: Line 127:
 
         }
 
         }
  
        /// <summary>
 
 
         /// Gets the description.
 
         /// Gets the description.
        /// </summary>
 
 
         public string Description
 
         public string Description
 
         {
 
         {
Line 164: Line 136:
 
         }
 
         }
  
        /// <summary>
 
 
         /// Gets the product ID.
 
         /// Gets the product ID.
        /// </summary>
 
 
         public string ProductID
 
         public string ProductID
 
         {
 
         {
Line 175: Line 145:
 
         }
 
         }
  
        /// <summary>
 
 
         /// Gets the publisher.
 
         /// Gets the publisher.
        /// </summary>
 
 
         public string Publisher
 
         public string Publisher
 
         {
 
         {
Line 186: Line 154:
 
         }
 
         }
  
        /// <summary>
 
 
         /// Gets the capabilities.
 
         /// Gets the capabilities.
        /// </summary>
 
 
         public IList Capabilities
 
         public IList Capabilities
 
         {
 
         {
Line 199: Line 165:
 
</code>
 
</code>
  
para conetar a view model com a página devemos adicionar a ViewModelLocator no App.xaml:   
+
== Implementando a View ==
 +
 
 +
Para conetar a view model com a página devemos adicionar a {{Icode|ViewModelLocator}} no '''App.xaml''':   
  
 
<code xml>
 
<code xml>
Line 286: Line 254:
 
</phone:PhoneApplicationPage>
 
</phone:PhoneApplicationPage>
 
</code>
 
</code>
 
 
  
 
== Exemplo Relacionado ==
 
== Exemplo Relacionado ==
  
 
* [[Criando uma página "Sobre" para aplicações em Windows Phone]]
 
* [[Criando uma página "Sobre" para aplicações em Windows Phone]]
[[en:How to use Cimbalino Windows Phone Toolkit - ApplicationManifestService]]
+
 
<!-- Translation --> [[en:How to use Cimbalino Windows Phone Toolkit - ApplicationManifestService<!-- Title only - not link -->]]
+
  
 
== Código Fonte ==
 
== Código Fonte ==
  
 
O código fonte pode ser obtido [https://github.com/saramgsilva/CimbalinoToolkitSamples/tree/master/How%20to%20use%20Cimbalino%20Windows%20Phone%20Toolkit%20Background%20-%20ApplicationManifestService aqui]
 
O código fonte pode ser obtido [https://github.com/saramgsilva/CimbalinoToolkitSamples/tree/master/How%20to%20use%20Cimbalino%20Windows%20Phone%20Toolkit%20Background%20-%20ApplicationManifestService aqui]
 +
<!-- Translation --> [[en:How to use Cimbalino Windows Phone Toolkit - ApplicationManifestService]]

Latest revision as of 03:03, 19 November 2013

Este artigo tem como objetivo mostrar como usar Cimbalino Windows Phone Toolkit Background – ApplicationManifestService.

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

Exemplo de código
Código fonte: 20ApplicationManifestService Example (github)

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

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

Contents

[edit] 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.Background - Projeto do toolkit contendo serviços para implementação do padrão de MVVM compatível com “background agents”.

Página resultante

[edit] Contruindo o exemplo

O código fonte pode ser obtido em Exemplo ApplicationManifestService (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:

[edit] Registando serviços

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

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

[edit] Implementando a ViewModel

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

    /// This class contains properties that the main View can data bind to.
public class MainViewModel : ViewModelBase
{
/// The public application url.
private readonly string _appUrl;
 
/// The application manifest.
private readonly ApplicationManifest _applicationManifest;
 
/// Initializes a new instance of the application Manifest Service.
public MainViewModel(IApplicationManifestService applicationManifestService)
{
_applicationManifest = applicationManifestService.GetApplicationManifest();
_appUrl = string.Concat("http://windowsphone.com/s?appid=", _applicationManifest.App.ProductId);
}
 
/// Gets the title.
public string Title
{
get
{
return _applicationManifest.App.Title;
}
}
 
/// Gets the author.
public string Author
{
get
{
return _applicationManifest.App.Author;
}
}
 
/// Gets the version.
public string Version
{
get
{
return _applicationManifest.App.Version;
}
}
 
/// Gets the description.
public string Description
{
get
{
return _applicationManifest.App.Description;
}
}
 
/// Gets the product ID.
public string ProductID
{
get
{
return _applicationManifest.App.ProductId;
}
}
 
/// Gets the publisher.
public string Publisher
{
get
{
return _applicationManifest.App.Publisher;
}
}
 
/// Gets the capabilities.
public IList Capabilities
{
get
{
return _applicationManifest.App.Capabilities.ToList();
}
}
}

[edit] Implementando a View

Para conetar a view model com a página devemos adicionar a ViewModelLocator no App.xaml:

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

e adicionar o binding na página principal:

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

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" />
</StackPanel>
 
<!-- ContentPanel - place additional content here -->
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0" >
<TextBlock TextWrapping="Wrap"
VerticalAlignment="Top" Height="50">
Title: <Run Text="{Binding Title}"/>
</TextBlock>
<TextBlock TextWrapping="Wrap"
VerticalAlignment="Top" Margin="0,50,0,0">
Author: <Run Text="{Binding Author}"/>
</TextBlock>
<TextBlock TextWrapping="Wrap"
VerticalAlignment="Top" Margin="0,100,0,0">
Version: <Run Text="{Binding Version}"/>
</TextBlock>
<TextBlock TextWrapping="Wrap"
VerticalAlignment="Top" Margin="0,150,0,0">
Description: <Run Text="{Binding Description}"/>
</TextBlock>
<TextBlock TextWrapping="Wrap"
VerticalAlignment="Top" Margin="0,300,0,0">
ProductID: <Run Text="{Binding ProductID}"/>
</TextBlock>
<TextBlock TextWrapping="Wrap"
VerticalAlignment="Top" Margin="0,350,0,0">
Publisher: <Run Text="{Binding Publisher}"/>
</TextBlock>
<TextBlock TextWrapping="Wrap" Text="Capabilities:"
VerticalAlignment="Top" Margin="0,400,0,0"/>
<ListBox DisplayMemberPath="Name" Margin="0,450,0,0"
ItemsSource="{Binding Capabilities}"/>
</Grid>
 
</Grid>
 
</phone:PhoneApplicationPage>

[edit] Exemplo Relacionado


[edit] Código Fonte

O código fonte pode ser obtido aqui

This page was last modified on 19 November 2013, at 03:03.
104 page views in the last 30 days.

Was this page helpful?

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

 

Thank you!

We appreciate your feedback.

×