简体   繁体   English

在Windows Universal App上拖放文件

[英]Drag and drop a file on Windows Universal App

How to Drag and drop a file on Windows Universal App? 如何在Windows Universal App上拖放文件?

The only tutorial I've found, is this one: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlDragAndDrop 我发现的唯一教程就是这个: https : //github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlDragAndDrop

However it operates on XAML UI objects, while I have a DirectX game and don't use XAML at all. 但是,它在XAML UI对象上运行,而我有DirectX游戏,根本不使用XAML。

All I want is to drag and drop a file onto the Application Window (not a single UI element but the entire window), and in an event callback get the file full path. 我只想将文件拖放到“应用程序窗口”(不是单个UI元素,而是整个窗口)上,并在事件回调中获取文件的完整路径。

I'm using C++, this needs to be for Windows 10 Universal App. 我正在使用C ++,这需要用于Windows 10 Universal App。

Could you please let me know why you don't want to use XAML for such kind of scenario? 您能否让我知道为什么您不希望在这种情况下使用XAML? Since the UWP XAML UI controls have very convenient support for drag-drop feature, and it also supports interop with DX via C++. 由于UWP XAML UI控件非常方便地支持拖放功能,并且还支持通过C ++与DX互操作。 This online tutorial could be helpful. 此在线教程可能会有所帮助。 From this online help, you can find out that you could customize your own control to not show UI at all. 从此联机帮助中,您可以发现可以自定义控件以完全不显示UI。

And if you want to implement dragging and dropping files without the help of XAML, it would require tremendous work: Dragging file to your UWP game means to share data among apps, so your implementation needs to follow UWP data sharing pattern , which means you need to re-code everything XAML UIElement has already encapsulated, eg: implementing DropTarget Control Pattern. 而且,如果您要在XAML的帮助下实现拖放文件,则需要进行大量工作:将文件拖放到UWP游戏中意味着要在应用之间共享数据,因此您的实现需要遵循UWP数据共享模式 ,这意味着您需要重新编码XAML UIElement已经封装的所有内容,例如:实现DropTarget Control Pattern。

For you case, if you only want to open file, then File Picker is more simple and convenient. 对于您而言,如果只想打开文件,则File Picker更加简单方便。 If you still want to support drag and drop, it is high recommended to interop XAML and DX. 如果仍要支持拖放,则强烈建议互操作XAML和DX。 Here you can find useful guideline . 在这里您可以找到有用的指南 You can build the app in C++, which would meet your concern about conserving memory and improving performance. 您可以使用C ++构建应用程序,这将满足您对节省内存和提高性能的关注。

Please let me know if you have any question. 如果您有任何疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM