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
2
Answers
I successfully triggered the
share window
via a button withICommand
in Windows 11 like below: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 isMicrosoft Visual Studio Community 2022 (64-bit) - Current Version 17.3.6
Update:
The
Microsoft.Maui.ApplicationModel.DataTransfer.Share
doesn’t work inWindows 10
,however it works inWindows 11
. You can raise a new issue in Github.Try updating workloads. It fixed file sharing issue in my case.
PowerShell command line:
dotnet workload update
.