Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Como partilhar um link usando Cimbalino Windows Phone Toolkit

From Wiki
Jump to: navigation, search

Este artigo tem como objetivo mostrar como usar Cimbalino Windows Phone Toolkit - ShareLinkService.

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

Exemplo de código
Código fonte: ShareLinkService 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 saramgsilva em 23 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;

  • IShareLinkService é a interface (Cimbalino toolkit- código fonte aqui) que representa o serviço com a capacidade de partilhar "links" na rede social configurada no dispositivo. A Implementação é ShareLinkService.

Ecrã do exemplo criado

ShareLinkService.png

Contruindo o exemplo

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:

  1.         /// Initializes a new instance of the ViewModelLocator class.
  2.         public ViewModelLocator()
  3.         {
  4.             ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
  5.  
  6.             if (!SimpleIoc.Default.IsRegistered<IShareLinkService>())
  7.             {
  8.                 SimpleIoc.Default.Register<IShareLinkService, ShareLinkService>();
  9.             }
  10.  
  11.             SimpleIoc.Default.Register<MainViewModel>();
  12.         }
  13.  
  14.         public MainViewModel MainViewModel
  15.         {
  16.             get
  17.             {
  18.                 return ServiceLocator.Current.GetInstance<MainViewModel>();
  19.             }
  20.         }
  21.  
  22.         public static void Cleanup()
  23.         {
  24.             // TODO Clear the ViewModels
  25.         }
  26.     }

Implementando a ViewModel

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

  1. public class MainViewModel : ViewModelBase
  2.     {
  3.         /// The share link service.
  4.         private readonly IShareLinkService _shareLinkService;
  5.  
  6.         /// The public application url.
  7.         private readonly string _appUrl;
  8.  
  9.         /// Initializes a new instance of the share Link Service.
  10.         public MainViewModel(IShareLinkService shareLinkService)
  11.         {
  12.             _shareLinkService = shareLinkService;
  13.  
  14.             ShareSocialNetworkCommand = new RelayCommand(ShareSocialNetwork);
  15.             _appUrl = string.Concat("http://windowsphone.com/s?appid=8df00038-1b7a-406b-b33f-37a78b17348c");
  16.         }
  17.  
  18.         /// Gets the share social network command.
  19.         public ICommand ShareSocialNetworkCommand { get; private set; }
  20.  
  21.         /// The share social network.
  22.         private void ShareSocialNetwork()
  23.         {
  24.             const string Message = "This application is amazing, should try it! See in";
  25.             _shareLinkService.Show("Cimbalino Toolkit Sample", Message, new Uri(_appUrl, UriKind.Absolute));
  26.         }
  27.     }

Implementando a View

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

  1. <phone:PhoneApplicationPage x:Class="CimbalinoSample.MainPage"
  2.                             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.                             xmlns:cimbalino="clr-namespace:Cimbalino.Phone.Toolkit.Behaviors;assembly=Cimbalino.Phone.Toolkit"
  5.                             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6.                             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
  7.                             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8.                             xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
  9.                             xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
  10.                             DataContext="{Binding MainViewModel,
  11.                                                   Source={StaticResource Locator}}"
  12.                             FontFamily="{StaticResource PhoneFontFamilyNormal}"
  13.                             FontSize="{StaticResource PhoneFontSizeNormal}"
  14.                             Foreground="{StaticResource PhoneForegroundBrush}"
  15.                             Orientation="Portrait"
  16.                             SupportedOrientations="Portrait"
  17.                             shell:SystemTray.IsVisible="True"
  18.                             mc:Ignorable="d">
  19.  
  20.     <!--  LayoutRoot is the root grid where all page content is placed  -->
  21.     <Grid x:Name="LayoutRoot" Background="Transparent">
  22.         <Grid.RowDefinitions>
  23.             <RowDefinition Height="Auto" />
  24.             <RowDefinition Height="*" />
  25.         </Grid.RowDefinitions>
  26.  
  27.         <!--  TitlePanel contains the name of the application and page title  -->
  28.         <StackPanel x:Name="TitlePanel"
  29.                     Grid.Row="1"
  30.                     Margin="0,5,12,396">
  31.             <TextBlock Margin="12,0"
  32.                        Style="{StaticResource PhoneTextTitle2Style}"
  33.                        Text="Cimbalino Toolkit Sample" />
  34.         </StackPanel>
  35.         <TextBlock Grid.RowSpan="2"
  36.                    Margin="12,50,-3,487"
  37.                    Style="{StaticResource PhoneTextTitle3Style}"
  38.                    TextWrapping="Wrap">
  39.             This samples has the goal to show how to use Cimbalino Toolkit - ShareLinkService.
  40.         </TextBlock>
  41.         <!--  ContentPanel - place additional content here  -->
  42.         <Grid x:Name="ContentPanel"
  43.               Grid.Row="1"
  44.               Margin="12,0,12,0" />
  45.         <i:Interaction.Behaviors>
  46.             <cimbalino:ApplicationBarBehavior>
  47.  
  48.                 <cimbalino:ApplicationBarIconButton Command="{Binding ShareSocialNetworkCommand,
  49.                                                                       Mode=OneTime}"
  50.                                                     IconUri="/Images/appbar.share.png"
  51.                                                     Text="Share it" />
  52.             </cimbalino:ApplicationBarBehavior>
  53.         </i:Interaction.Behaviors>
  54.     </Grid>
  55.  
  56. </phone:PhoneApplicationPage>

Exemplo Relacionado

Código Fonte

O código fonte pode ser obtido aqui.

This page was last modified on 23 November 2013, at 19:04.
151 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.

×