Working With Share Link Task in Windows Phone 8

Introduction

In this article we will learn about the Share Link Task. This task enables the user to share a link from the app itself on various social media and other sharing platforms. It can be a very useful feature for promoting your app on various platforms. Let's see how to use it.

Share Link Task

This is a kind of launcher provided by Windows Phone to launch the share screen from an app so that the user can share the link. The task can be customized with various properties for its proper use. 

Before using this task we need to include the following namespace:

using Microsoft.Phone.Tasks;

To use this task we need to do the following steps:

  1. Create a new instance of the Save appointment task.

    Microsoft.Phone.Tasks.ShareLinkTask slt = new ShareLinkTask();
     

  2. Next is to set various properties of this task.

    slt.LinkUri = newUri("url_to_share",UriKind.Relative);

    slt.Message = "Shared link using windows phone.";

    slt.Title = "How to share links";

     

  3. Finally, show this task by calling the Show method.

    slt.Show();

Properties that we can set for this task are as follows:

  • Link Uri

    Sets the link URI that will be displayed in the sharing dialog.
     
  • Message

    Sets the message that will accompany the link when it is shared.
     
  • Title

    Sets the title of the link to be shared. 

 

Demo

The following code demonstrates how we can use the Share Link Task for sharing a link from our app.

XAML

<phone:PhoneApplicationPage

    x:Class="Demo.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}"

    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="Demo" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>

            <TextBlock  Text="Demo" Margin="9,-7,0,0" FontSize="40" />

        </StackPanel>

 

        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

            <StackPanel Orientation="Vertical">

                <TextBlock Text="Share Link" FontSize="45" Height="106"></TextBlock>

                <TextBox Name="urlTxt" Text="Url"></TextBox>

                <TextBox Name="msgTxt" Text="Message" TextWrapping="Wrap" Height="304"></TextBox>

                <TextBox Name="titleTxt" Text="Title"></TextBox>

                <Button x:Name="btnShare" Click="btnOpen_Click"  Content="Share" HorizontalAlignment="Left" Width="436" Height="80" VerticalAlignment="Bottom" Margin="10,0,0,0"/>

            </StackPanel>

        </Grid>

    </Grid>

</phone:PhoneApplicationPage>

C# Code Behind

using Microsoft.Phone.Controls;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Diagnostics;

using Microsoft.Phone.Tasks;

using System.Windows.Media;

 

namespace Demo

{

    public partial class MainPage : PhoneApplicationPage

    {

        // Constructor

        public MainPage()

        {

            InitializeComponent();

        }

 

        private void btnOpen_Click(object sender, RoutedEventArgs e)

        {

            /* Step 1 */

            Microsoft.Phone.Tasks.ShareLinkTask slt = new ShareLinkTask();

 

            /* Step 2 */

            slt.LinkUri = new Uri("",UriKind.Relative);

            slt.Message = "Shared link using windows phone.";

            slt.Title = "How to share links";

 

            /* Step 3 */

            slt.Show();

        }

    }

}

The Show method is used to launch the task.

 

Output

 
 
 
 
 
 

Up Next
    Ebook Download
    View all
    Learn
    View all