【问题标题】:Drag and drop onto SwapChainPanel in UWP app在 UWP 应用中拖放到 SwapChainPanel
【发布时间】:2019-01-08 10:52:42
【问题描述】:

我们有一个使用 SwapChainPanel 来呈现 2D 内容的 UWP 应用程序,我们希望能够在其上拖放文件。

第一种方法:

首先我只是尝试使用 SwapChainPanel 本身上的事件,它们从未被调用。

        <SwapChainPanel x:Name="swap" AllowDrop="True" DragEnter="Swap_DragEnter" >

        </SwapChainPanel>

第二种方法:

然后我尝试在 SwapChainPanel 中放置一个透明矩形。拖动事件现在可以工作,但 SwapChainPanel 现在根本不接收任何指针事件。

        <SwapChainPanel x:Name="swap" >
            <Rectangle Fill="Transparent" AllowDrop="True" DragEnter="Swap_DragEnter"  />
        </SwapChainPanel>

第三种方法:

SwapChainPanel 似乎不像普通的 XAML 控件那样工作,所以我假设我必须在运行面板的 c++ 代码中处理拖动事件。但是好像没有什么办法,只有基本指针事件的引用。

    ...
    coreInput_ = renderPanel_.CreateCoreIndependentInputSource(deviceTypes);

    coreInput_.PointerPressed({this, &InputManagerImpl::onPointerPressed});
    coreInput_.PointerMoved({this, &InputManagerImpl::onPointerMoved});
    coreInput_.PointerReleased({this, &InputManagerImpl::onPointerReleased});
    coreInput_.PointerEntered({this, &InputManagerImpl::onPointerEntered});
    coreInput_.PointerExited({this, &InputManagerImpl::onPointerExited});
    coreInput_.PointerCaptureLost({this, &InputManagerImpl::onPointerCaptureLost});
    coreInput_.PointerWheelChanged({this, &InputManagerImpl::onPointerWheelChanged});
    ...

所以现在我不确定如何执行拖放操作?谢谢!

【问题讨论】:

  • 我认为您可以将SwapChainPanel 放在Grid 中,然后将拖放到网格上。不过,您可能会失去与渲染场景的交互。而且,确保它是透明的,它接受用户输入。
  • @Stefan 谢谢,你是对的,把它放在网格里确实有效。
  • 我会把它作为答案发布然后XD

标签: c# .net uwp winrt-xaml


【解决方案1】:

我认为您可以将 SwapChainPanel 放在 Grid 中,然后将拖放到网格上。不过,您可能会失去与渲染场景的交互。而且,确保它是透明的,它接受用户输入。

例如:

<!-- add attributes and drag and drop functionality on Grid -->
<Grid AllowDrop="True" DragEnter="Swap_DragEnter"> 
     <SwapChainPanel x:Name="swap">

     </SwapChainPanel>
</Grid>

【讨论】:

  • SwapChainPanel 已经是一个 Grid,但你必须把它放在另一个 Grid 中才能正常工作,我猜微软在这里采取了古怪的方法。
猜你喜欢
  • 2019-06-24
  • 1970-01-01
  • 2017-05-14
  • 2018-12-23
  • 1970-01-01
  • 2019-06-10
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
相关资源
最近更新 更多