MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Sharing a Winui3 WebView2 CapturePreviewAsync Bitmap Picture
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
What happened?
I have successfully set up sharing from my WinUI3 app utilizing the interop functionality. All is working and when I select to share with Microsoft Mail the Data Package is working fine, although the bitmap isn't rendering in the NEW OUTLOOK app.
Although it does work in the OLD OUTLOOK
[System.Runtime.InteropServices.ComImport]
[System.Runtime.InteropServices.Guid("3A3DCD6C-3EAB-43DC-BCDE-45671CE800C8")]
[System.Runtime.InteropServices.InterfaceType(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)]
interface IDataTransferManagerInterop
{
IntPtr GetForWindow([System.Runtime.InteropServices.In] IntPtr appWindow,
[System.Runtime.InteropServices.In] ref Guid riid);
void ShowShareUIForWindow(IntPtr appWindow);
}
static readonly Guid _dtm_iid =
new Guid(0xa5caee9b, 0x8708, 0x49d1, 0x8d, 0x36, 0x67, 0xd2, 0x5a, 0x8d, 0xa0, 0x0c);
public async void WebView_ShareObject(object sender, RoutedEventArgs e)
{
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow);
IDataTransferManagerInterop interop =
Windows.ApplicationModel.DataTransfer.DataTransferManager.As
<IDataTransferManagerInterop>();
IntPtr result = interop.GetForWindow(hWnd, _dtm_iid);
var dataTransferManager = WinRT.MarshalInterface
<Windows.ApplicationModel.DataTransfer.DataTransferManager>.FromAbi(result);
InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
await WebViewService.WebView.CoreWebView2.CapturePreviewAsync(CoreWebView2CapturePreviewImageFormat.Png, stream);
RandomAccessStreamReference randomAccessStream = RandomAccessStreamReference.CreateFromStream(stream);
dataTransferManager.DataRequested += async void (sender, args) =>
{
args.Request.Data.Properties.Title = "Web Dive Sharing";
args.Request.Data.SetText("Sharing your webpage");
args.Request.Data.SetWebLink(new Uri(WebViewService.WebView.CoreWebView2?.Source));
args.Request.Data.SetBitmap(randomAccessStream);
args.Request.Data.RequestedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Link;
};
// Show the Share UI
interop.ShowShareUIForWindow(hWnd);
}
Importance
Moderate. My app's user experience is affected, but still usable.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
No response
SDK Version
No response
Framework
WinUI3/WinAppSDK
Operating System
Windows 10
OS Version
No response
Repro steps
}
Regression
No, this never worked
Last working version (if regression)
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.