0
votes

In my windows phone 8.1 universal app project I am trying to make a share option.

But when I click on the button (ShareCommand) the Share UI is not showing up, I have tried this in the emulator and on a device.

The event is correctly wired up since the DataRequested event gets called, but after this event there is no Share UI showing.

Here is the code I use in my ViewModel (using prism framework).

private DataTransferManager _dataTransferManager;    
private DelegateCommand _shareCommand;

// Share button
public DelegateCommand ShareCommand
    {
       get
       {
          return _shareCommand ?? (_shareCommand = new DelegateCommand(() =>
          {
              DataTransferManager.ShowShareUI();
          }));
       }
    }

public override async void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode, Dictionary<string, object> viewModelState)
{
    base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);

    // get data transfer manager and register events
    _dataTransferManager = DataTransferManager.GetForCurrentView();
    _dataTransferManager.DataRequested += DataTransferMangerDataRequested;
    _dataTransferManager.TargetApplicationChosen += DataTransferMangerTargetApplicationChosen;
 }

 public override void OnNavigatedFrom(Dictionary<string, object> viewModelState, bool suspending)
 {
      base.OnNavigatedFrom(viewModelState, suspending);

      // clean up events
      _dataTransferManager.DataRequested -= DataTransferMangerDataRequested;
      _dataTransferManager.TargetApplicationChosen -= DataTransferMangerTargetApplicationChosen;
 }

 private void DataTransferMangerTargetApplicationChosen(DataTransferManager sender, TargetApplicationChosenEventArgs args)
 {               
 }

 private void DataTransferMangerDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
 {
      var request = args.Request;
      var deferral = request.GetDeferral();

      request.Data.Properties.Title = "title test";
      request.Data.Properties.Description = "description test";
      request.Data.SetText("test hello");
      request.Data.SetUri(new Uri("https://www.google.com"));

      request.FailWithDisplayText("fail");

      deferral.Complete();
 }

I have tried setting different properties in the DataRequested event but still nothing.

Does anyone know what it could be? Do I need to set some permissions?

Edit: Ok, weird I tried this in a new solution with only this code and it is working fine. But no idea why its not working in my current solution.

1

1 Answers

1
votes

Ok I found out what was causing the problem.

I had to remove this, since this will cancel the operation. (I thought this will show if it failed for some reason and not cancel directly).

request.FailWithDisplayText("fail");