1

I have a page in my application which share simple text, not working properly.

Steps to produce this functionality.

  1. Go to Page click share it shows application which can share.

  2. Tap back button => click again on share button.

  3. This will not open share screen this time.

Pasting my code below:

    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
        _dataTransferManager.DataRequested -= OnDataRequested;
        this.navigationHelper.OnNavigatedFrom(e);
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        _dataTransferManager = DataTransferManager.GetForCurrentView();
        _dataTransferManager.DataRequested += OnDataRequested;
        this.navigationHelper.OnNavigatedTo(e);
    }

    private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs e)
    {
        e.Request.Data.Properties.Title =  obj.Title;
        HtmlDocument doc = new HtmlDocument();
        doc.LoadHtml(obj.Description);
        string html = "";
        foreach (HtmlNode item in doc.DocumentNode.Descendants())
        {
            if (item.Name == "body")
            {
                html = item.InnerHtml;
            }
        }
        e.Request.Data.Properties.Description = html;
        e.Request.Data.SetText(html);
    }

    private void AppBarButton_Click_1(object sender, RoutedEventArgs e)
    {
        //DataTransferManager.ShowShareUI();
        if (CMSService.IsConnectedToInternet())
        {
            DataTransferManager.ShowShareUI();
        }
        else
        {
            ContentText.Text = App.GetResource("NoInternetAlert");
            AlertMessage.ShowAsync();
        }
    }

And while debugging share works all the time.

Yawar
  • 1,924
  • 3
  • 29
  • 39

1 Answers1

1

I suspect that the problem is because you unsubscribe from _dataTransferManager.DataRequested -= OnDataRequested; in OnNavigatedFrom event. This will work fine when debugging, hence this event won't be raised - while debuging PLM is disabled and Suspending/Resuming events won't be raised.

When running app normal, suspension will invoke OnNavigatedFrom, but OnNavigatedTo won't be raised upon resuming, thus there won't be susbscription to _dataTransferManager.DataRequested += OnDataRequested;.

In this case you probably can use Suspending/Resuming (or other) events to handle DataTransferManager.

Community
  • 1
  • 1
Romasz
  • 29,662
  • 13
  • 79
  • 154
  • I don't know how to register suspending/Resuming event on a single page – Yawar Aug 17 '15 at 07:21
  • You are right, exactly same thing is happening now problem is that there is no event firing while resuming the application. If you tell me any event that fired on resuming it will be helpful – Yawar Aug 17 '15 at 07:29
  • Or I can only unregister this datarequest event on navigating back – Yawar Aug 17 '15 at 07:30
  • @Yawar Everything depends on what you need to achieve. Your app also should handle suspension properly. – Romasz Aug 17 '15 at 07:38