简体   繁体   English

C#UWP-如何获取对象的拖动图像?

[英]C# UWP - How to get an object's drag image?

How can I get a copy of the drag image for an item I'm dragging in my application? 如何为我在应用程序中拖动的项目获取拖动图像的副本?

The DragStarting event contains a DragStartingEventArgs object that includes a DragUI object whose description is, " The visual representation of the data being dragged. " Ideally, I'd like to do something like this within the DragStarting event: DragStarting事件包含一个DragStartingEventArgs对象,该对象包含一个DragUI对象,其描述为“ 正在拖动的数据的可视表示。 ”理想情况下,我想在DragStarting事件中执行以下操作:

    private void OnDragStarting( UIElement sender, DragStartingEventArgs args )
    {
        // Create a new bitmap image object
        var dragImage = new BitmapImage();

        // Assign the drag image to the new bitmap image object
        dragImage = args.DragUI. ????
    }

However, there doesn't seem to be a way to get the drag image from the DragUI object. 但是,似乎没有办法从DragUI对象获取拖动图像。 DragUI contains only "Set*" methods, and no "Get*" methods. DragUI仅包含“ Set *”方法,而没有“ Get *”方法。

Is there a way to get the drag image as the drag operation begins? 在拖动操作开始时,是否可以获取拖动图像?

You can use DataView.GetStorageItemsAsync() to receive the items you dragged into your applications. 您可以使用DataView.GetStorageItemsAsync()来接收拖动到应用程序中的项目。

<Grid AllowDrop="True" DragOver="Image_drop_drag_over_ui" Drop="image_drop"/>

//C# code // C#代码

public async void Image_Drop(object sender, DragEventArgs e)
{
     if (e.DataView.Contains(StandardDataFormats.StorageItems))
     {
        List<StorageFile> received_images = new List<StorageFile>();
        var items = await e.DataView.GetStorageItemsAsync();
        var storageFile = items[0] as StorageFile;
        received_images.Add(storageFile);
     }
}
private void Image_drop_drag_over_ui(object sender, DragEventArgs e)
{
     e.AcceptedOperation = DataPackageOperation.Copy;
     e.DragUIOverride.Caption = "Drop receipt";
     e.DragUIOverride.IsCaptionVisible = true; 
}

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

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