Today we learn how to share content in Windows 8 Apps using C#. I will create an application for sharing any content via email.
A Sharing feature in an application allows the user to connect and share content with their friends and family and update that conent. The application that enables the user to share content is a best practice and encourages more people to use the application as it connects the user over the internet.
The Sharing feature in Windows 8 Apps enables the user to share content such as text, images, links, files etc. that helps the user to connect with the people. The user can share content over Facebook, SkyDrive, Email etc. thereby helping him to keep updated.
Now, let's start to create a Windows 8 application that helps the user to share content and connect with people though the application.
Step 1
Create a Blank Application using C#.
Step 2
Add the followiing namespaces to your application:
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
Step 3
To enable sharing in the application, I will get the instance of the DataTransferManager class. This class is used to assign the current window to sharing.
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
Step 4
After getting the DataTransferManager obect we need to add an event handler of this class that supports sharing. This event is known as the DataRequested event which is fired when the user opens the share window. You need to set this code in your initializing function.
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager,
DataRequestedEventArgs>(this.ShareTextHandler);
Step 5
In the event handler declared above, you need to get a DataRequest object and add some properties like title and description to be displayed when the share charm is opened.
DataRequest request = e.Request;
request.Data.Properties.Title = "Share Text Example";
request.Data.Properties.Description = "A demonstration that shows how to share text.";
Step 6
Now, the important thing here is to set the text or content to be shared and add to the DataPackage Class. To set the text to be shared using a textbox, I will create a simple user interface that contains one textbox, as in:
request.Data.SetText(ShareText.Text);
Step 7
Afer setting up everything for sharing, it's time to open the share charm. For this I created a button that opens the share window; see:
DataTransferManager.ShowShareUI();
In the preceding code I use the ShowShareUI() method to open the share windows programmatically. You can also use a tap or charm option to open the share window.
using System;
using Windows.ApplicationModel;
using Windows.ApplicationModel.DataTransfer;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;



Gowtham RajamanickamPosted Apr 10, 2016, 1:30 AM
keep writing
Gowtham RajamanickamPosted Apr 10, 2016, 1:30 AM
nice article
salman ansariPosted Feb 27, 2013, 11:40 AM
Nice Article mainly for begging...
naren draneditedPosted Jan 24, 2013, 5:21 AMEdited Jan 24, 2013, 5:22 AM
Here one text box is used. more than one textbox means how to do? The message should come one line after another.