-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please simply wrap the DataTransferManager interop class #3777
Comments
Related to #1063 |
通过使用Vanara.Windows.Shell提供的Win32 API包装,应当能够将其简化为以下代码。但是确实WAS应该提供官方实现。 Shell32.IDataTransferManagerInterop Interop = DataTransferManager.As<Shell32.IDataTransferManagerInterop>();
Interop.GetForWindow(<Your window handle>, Shell32.IID_DataTransferManager, out IntPtr ObjectPointer).ThrowIfFailed();
DataTransferManager.FromAbi(ObjectPointer).DataRequested += (s, e) =>
{
DataRequestDeferral Deferral = e.Request.GetDeferral();
try
{
e.Request.Data = new DataPackage();
e.Request.Data.Properties.Title = <Your file name>;
e.Request.Data.Properties.Description = <Your file type>;
e.Request.Data.SetStorageItems(new IStorageItem[] { <Your file that want to share> }, false);
}
catch (Exception ex)
{
e.Request.FailWithDisplayText(ex.Message);
}
finally
{
Deferral.Complete();
}
};
Interop.ShowShareUIForWindow(<Your window handle>).ThrowIfFailed(); |
See reference microsoft/CsWinRT#1528 |
Describe the bug
Please simply wrap the DataTransferManager interop class
At present in desktop applications, if we want to invoke DataTransferManager class methods, the need to import IDataTransferManagerInterop interface, and implement the corresponding operation in accordance with the corresponding methods, it is a bit too cumbersome. Hope future versions can be a simple packaging IDataTransferManagerInterop interface, to call DataTransferManager method in a class.
目前在桌面应用中,如果我们想要调用DataTransferManager类的方法,需要自己导入IDataTransferManagerInterop接口,并按照相应的方法实现对应的操作,这有点太繁琐了。希望未来的版本中可以简单包装一下IDataTransferManagerInterop接口,能更快的调用DataTransferManager类中的方法。
This is the code in the official example.
这是官方示例中的代码。
// MainWindow.xaml.cs
...
public sealed partial class MainWindow : Window
{
...
[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);
}
}
...
Steps to reproduce the bug
None
Expected behavior
Please provide a DataTransferManagerInterop static class, the class has achieved IDataTransferManagerInterop interface, and provides the corresponding interactions. The following code
请提供一个DataTransferManagerInterop静态类,这个类内部已经实现了IDataTransferManagerInterop接口,并提供了相应的交互操作。如下面的代码
In this wrapped class, if we need to use the methods provided in the DataTransferManager class, we only need one line of code:
在这个包装好的类中,如果我们需要使用DataTransferManager类中提供的方法,只需要一行代码:
DataTransferManager dataTransferManager = DataTransferManagerInterop.GetForWindow(/need to input window handle/);
To display the shared window, just:
想要显示共享窗口,只需要:
DataTransferManagerInterop.ShowShareUI(/need to input window handle/);
It can be called quickly.
即可快速调用。
Screenshots
Defined static class
定义的静态类
快速调用示例
Quick call example
The definition of the DataTransferManagerInterop static class reference is DisplayInformationInterop static class definition
这个DataTransferManagerInterop静态类的定义参考的是DisplayInformationInterop静态类的定义
NuGet package version
Windows App SDK 1.4 Preview 1: 1.4.230628000-preview1
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 22H2 (22621, 2022 Update)
IDE
Visual Studio 2022
Additional context
None
The text was updated successfully, but these errors were encountered: