如何自定义拖放过程中显示的视图?

How can I customize the view shown during drag and drop?

我在我的 UWP 应用程序上进行了拖放设置,我想自定义用户拖动的视图。目前它与 ListViewItem 完全相同,但它有一个 Border(提供背景和圆角边缘)我不想在拖动视图中显示。

这只是一个简单的 CanDragItemsAllowDropDragItemsStartingDragEnterDrop 事件挂钩。

有办法吗?

but that has a Border(providing a background and rounded edges) I don't want to show in the dragging view.

要去掉ListviewItemBolder,不需要自定义拖拽视图,只需将Bolder元素的子元素设置为[=15=即可],为Bolder子元素如TextBlock设置CanDrag 属性后,拖动item时不会看到Bolder效果。代码示例如下:

    <ListView x:Name="SourceListView"
              Header="SourceListView"
              SelectionMode="Extended">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Border Background="Pink"
                        BorderBrush="Gray"
                        BorderThickness="2"
                        CornerRadius="10">
                    <TextBlock Text="{Binding text}"  DragStarting="TextBlock_DragStarting" CanDrag="True"  />
                </Border>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

I'd like to customize the view that the user drags.

如果您仍想自定义拖动 UI,可以直接使用现有的 class DragUIOverride 自定义拖动视图。 例如你不想在拖动视图中显示箭头,你可以在 DragOver 事件中设置 IsGlyphVisible 属性 像这样:

 private void cnvDrop_DragOver(object sender, DragEventArgs e)
 {           
    e.DragUIOverride.IsGlyphVisible = false;
 }

官方示例是XamlDragAndDrop,场景2显示了关于DragUI自定义的详细信息。