So after a few hours searching on forums I could 'mount' that solution:
Add these lines on your construtor after the this.InitializeComponent(); line.
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView(); dataTransferManager.DataRequested += ShareTextHandler;
ShareTextHandler will be called by DataTransferManager after you call the DataTransferManager.ShowShareUI() method.
private async void ShareTextHandler(DataTransferManager sender, DataRequestedEventArgs e) { DataRequest request = e.Request; DataRequestDeferral deferral = e.Request.GetDeferral(); // Loading the image file we want to share Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile sampleFile = await storageFolder.GetFileAsync("yourimagefile.png"); //Configuring the request request.Data.Properties.Title = "Post title"; //Mandatory request.Data.SetText("Some description"); //Optional request.Data.SetStorageItems(new List() { file }); deferral.Complete(); }
Add the DataTransferManager.ShowShareUI() method on your button click event or whatever as you want it to be called.
private void OnClick_ShareButton(object sender, RoutedEventArgs e) { DataTransferManager.ShowShareUI(); }
No comments:
Post a Comment