1

On my .Net MAUI app, I need to use Microsoft.Maui.ApplicationModel.DataTransfer.Share to share some text. I followed this documentation: https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/data/share?view=net-maui-7.0&tabs=windows

And this is my code:

    [ICommand]
    private async Task ShareAsync()
    {
        string text = $"Some text";

        await Share.RequestAsync(new ShareTextRequest
        {
            Text = text,
            Title = "Calculation Results"
        });
    }

This works well on iOS and Android, but when I run it on Windows 10 in Visual Studio, executing Share.RequestAsync() does not do anything. No exception is thrown. It just quietly passes this line... and nothing happens. Can this be fixed?

ADDED:

I created a sample project here: https://github.com/DavidShochet/MauiApp1

Alexandar May - MSFT
  • 6,536
  • 1
  • 8
  • 15
David Shochet
  • 5,035
  • 11
  • 57
  • 105
  • I've got similar issue with `ShareFileRequest`. It used to work fine couple weeks ago, but now the share window pops up after firing `Share.RequestAsync` but no sharing options are available. Instead there is only a message: "This app can't share tight now". The same code works fine on Android. – Artur Wyszomirski Dec 30 '22 at 12:19

2 Answers2

1

I successfully triggered the share window via a button with ICommand in Windows 11 like below:


public ICommand Mycommand { private set; get; }
public MainPage()
{
     InitializeComponent();
     Mycommand = new Command(


     async() =>
     {
         string text = $"Some text";
         await Share.Default.RequestAsync(new ShareTextRequest

         {

                    Text = text,

                    Title = "Calculation Results"

                });
            });

     BindingContext = this;
}

And this should work as expected in Windows or other platforms. I would suggest that you can upgrading your VS to the lasted one. My VS version is Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.3.6

Update:

The Microsoft.Maui.ApplicationModel.DataTransfer.Share doesn't work in Windows 10 ,however it works in Windows 11. You can raise a new issue in Github.

Alexandar May - MSFT
  • 6,536
  • 1
  • 8
  • 15
  • Thank you for your answer. However, I use my code not from page's code-behind, but from the PageModel, as my app uses MVVM. I do have the latest version of Visual Studio. – David Shochet Dec 02 '22 at 14:22
  • Thanks for your response! What is your Operating System for your machine? Mine is Win11 E. Also, could you please create a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) via github repo link? – Alexandar May - MSFT Dec 05 '22 at 02:26
  • 1
    I added the project to my original question. I have Windows 10. – David Shochet Dec 05 '22 at 15:22
0

Try updating workloads. It fixed file sharing issue in my case.

PowerShell command line: dotnet workload update.