Introduction
As a Smartphone user, it's always the smart way to share a picture or a piece of text on a single tap. Whether you are on Windows Phone OS or on Android, you can share your captured picture with a single tap with your social friends.
So, we have decided to use this feature from C#.
Agenda
- Share Status as Text
- Share a Picture as a selected Image
- Share a Link as a Facebook path.
Procedures
Step 1
Before we proceed further, try to create a look alike UI in your project. And add a using Microsft.Phone.Task namespace in the backend of the C# page.
As per your needs, name your controls according to your comfort.
Step 2
I want to target the "Share Status" first. On the Share Status Button's click event handler use these lines of code.
- <code>
-
- ShareStatusTask status = new ShareStatusTask();
- status.Status = myStatus.Text;
-
-
- status.Show();
- </code>
Above, I tried to create an instance of a ShareStatus Task of the Microsoft.Phone.Tasks namespace. And then assign it to the textbox's text to the Status property. Last, call the show() method to render it.
Step 3
We are now done with the Share Status Task. Let's move to the Share Media Task where we share a picture of from our Photo Gallery.
To do this, we need an extra task called PhotoChooserTask . It allows you to choose an image from the Photo Gallery.
- private void btnShareMedia_Click(object sender, RoutedEventArgs e)
- {
-
- PhotoChooserTask choosePhoto = new PhotoChooserTask();
- choosePhoto.Completed += choosePhoto_Completed;
- choosePhoto.Show();
- }
-
- void choosePhoto_Completed(object sender, PhotoResult e)
- {
-
- ShareMediaTask media = new ShareMediaTask();
- media.FilePath = e.OriginalFileName.ToString();
- media.Show();
- }
Here, we have initiated an instance of the PhotoChooserTask and then raised the Completed event.
And in the event handler we have assigned e.OriginalFileName to the FilePath of the Share Task.
Step 4
What if I want to share a link? Then I need to use another predefined task for this. In this step, we will discover how to do this.
- private void btnShareLink_Click(object sender, RoutedEventArgs e)
- {
- ShareLinkTask link = new ShareLinkTask();
- link.LinkUri = new Uri("http://facebook.com/elmnt.abhishek", UriKind.Absolute);
- link.Show();
- }
In all the three tasks, we have done the same. Here, we have used the Link Uri property that accepts the URI type. So, we have ed our Facebook's profile as an absolute URI.
Conclusion
In this article, we have listed all the three predefined tasks under Microsft.Phone.Task to share. For any confusion, you can refer to the attached file.