1
votes

i am trying to take a picture and video from within the app and trying to share it through share charm but i am having a problem doing that. After i take the pic ,the share charm says it has trouble sharing the image. This is my code .Can anybody please let me know what i am doing wrong.

namespace Temp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class Page1 : Page
    {

        private StorageFile _photo; // Photo file to share
        private StorageFile _video; // Video file to share





        private async void OnCapturePhoto(object sender, TappedRoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();
            var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                _photo = file;
                DataTransferManager.ShowShareUI();
            }
        }



        private async void OnCaptureVideo(object sender, TappedRoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();
            camera.VideoSettings.Format = CameraCaptureUIVideoFormat.Wmv;
            var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Video);

            if (file != null)
            {
                _video = file;
                DataTransferManager.ShowShareUI();
            }
        }

        void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            var request = args.Request;


            if (_photo != null)
            {
                request.Data.Properties.Description = "Component photo";
                var reference = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(_photo);
                request.Data.Properties.Thumbnail = reference;
                request.Data.SetBitmap(reference);
                _photo = null;

            }
            else if (_video != null)
            {
                request.Data.Properties.Description = "Component video";
                List<StorageFile> items = new List<StorageFile>();
                items.Add(_video);
                request.Data.SetStorageItems(items);
                _video = null;
            }

        }

      }


        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;

        }







}
1

1 Answers

1
votes

In order for your app to share, you must set the Title of the DataPackagePropertySet and at least one of the "SetXXX" methods. If you do not, you'll see the following message when trying to share "There was a problem with the data from ."

So add request.Data.Properties.Title = "Title_of_photo_or_video"; in OnDataRequested event.