C# 拖放中的自定义接受操作
我正在制作一个图书馆管理软件。这是屏幕截图: 我实现了一些功能,比如将一本书拖到删除图标中以删除该书。但有两个障碍:C# 拖放中的自定义接受操作,c#,uwp,drag-and-drop,uwp-xaml,user-feedback,C#,Uwp,Drag And Drop,Uwp Xaml,User Feedback,我正在制作一个图书馆管理软件。这是屏幕截图: 我实现了一些功能,比如将一本书拖到删除图标中以删除该书。但有两个障碍: DataPackageOperation只有四种可能:复制、链接、移动无。因此,四次之后,很难区分书落在哪个AppBarButton上 我计划向命令栏添加更多项。但只有四种可能的操作 我需要一种方法来给用户一个定制的反馈,关于哪个AppBarButton是当前拖过的书。DataPackageOperation只包含四个。其中,“None”不能使用(因为它会让人困惑)。有没有办法
private void TargetTextBox_DragEnter(object sender, Windows.UI.Xaml.DragEventArgs e)
{
/// Change the background of the target
VisualStateManager.GoToState(this, "Inside", true);
bool hasText = e.DataView.Contains(StandardDataFormats.Text);
e.AcceptedOperation = hasText ? DataPackageOperation.Copy : DataPackageOperation.None;
if (hasText)
{
e.DragUIOverride.Caption = "Drop here to insert text";
// Now customize the content
if ((bool)HideRB.IsChecked)
{
e.DragUIOverride.IsGlyphVisible = false;
e.DragUIOverride.IsContentVisible = false;
}
else if ((bool)CustomRB.IsChecked)
{
var bitmap = new BitmapImage(new Uri("ms-appx:///Assets/dropcursor.png", UriKind.RelativeOrAbsolute));
// Anchor will define how to position the image relative to the pointer
Point anchor = new Point(0,52); // lower left corner of the image
e.DragUIOverride.SetContentFromBitmapImage(bitmap, anchor);
e.DragUIOverride.IsGlyphVisible = false;
e.DragUIOverride.IsCaptionVisible = false;
}
// else keep the DragUI Content set by the source
}
}
答案可以简化。“只需在拖动输入函数中添加此行:
e.DragUIOverride.Caption=“一些文本”