#711 – 在拖拽的过程中改变鼠标样式(Changing the Mouse Cursor While Dragging)
来源:互联网 发布:js导航代码 编辑:程序博客网 时间:2024/05/18 22:42
原文地址:https://wpf.2000things.com/2012/12/13/711-changing-the-mouse-cursor-while-dragging/
在WPF拖拽的过程中,通过GiveFeedback 事件可以更改整个过程中鼠标的样式。在事件中,我们可以通过GiveFeedbackEventArgs.Effects 属性来判断当前位置的拖动效果,从而设置鼠标的样式。
下面的例子中,当拖动的效果为Copy的时候,我们改变鼠标为一个手的样式,来表示允许拖动数据。
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="45"> <Label Content="Data to drag" Background="AliceBlue" Padding="15,10" Margin="10" MouseLeftButtonDown="Label_MouseLeftButtonDown" GiveFeedback="Label_GiveFeedback"/> <Label Content="Drag to here" Background="MediumSpringGreen" Padding="15,10" Margin="10" AllowDrop="True" Drop="Label_Drop"/></StackPanel>
private void Label_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){ DataObject data = new DataObject(DataFormats.Text, ((Label)e.Source).Content); DragDrop.DoDragDrop((DependencyObject)e.Source, data, DragDropEffects.Copy);} private void Label_Drop(object sender, DragEventArgs e){ ((Label)e.Source).Content = (string)e.Data.GetData(DataFormats.Text);} private void Label_GiveFeedback(object sender, GiveFeedbackEventArgs e){ if (e.Effects == DragDropEffects.Copy) { e.UseDefaultCursors = false; Mouse.SetCursor(Cursors.Hand); } else e.UseDefaultCursors = true; e.Handled = true;}
上面的最后一个函数中如果Effects 属性为Copy ,我们将鼠标设置为Cursors.Hand ,其它情况下为默认样式。
******************************************译者注*****************************************
GiveFeedbackEventArgs.Effects 属性是一个DragDropEffects类型的枚举,它有以下几种枚举值:
None - 放置目标不接受该数据。
Copy - 将拖动源中的数据复制到放置目标。
Move - 将拖动源的数据移动到放置目标。
Link - 将拖动源中的数据链接到放置目标。
Scroll - 拖动时可以滚动目标,以定位在目标中当前不可见的某个放置位置。
All - Copy、Link、Move 和 Scroll 效果的组合。
0 0
- #711 – 在拖拽的过程中改变鼠标样式(Changing the Mouse Cursor While Dragging)
- #713 – 在拖拽操作中使用控件预览图作为鼠标(Setting the Cursor to an Image of an UIElement While Dragging)
- 在网页中改变鼠标样式
- #230 – 当鼠标悬停在控件上时修改其放射渐变RadialGradientBrush(Changing a Radial Gradient as Mouse Over a Control)
- 用css 改变鼠标样式 改变cursor属性
- unity中改变鼠标的样式
- cursor 鼠标样式的几种样式
- #316 – 改变按钮的ClickMode(Changing the ClickMode of a Button)
- style.cursor 的可选值(鼠标的各种样式)
- style.cursor 的可选值(鼠标的各种样式)
- style.cursor 的可选值(鼠标的各种样式)
- style.cursor 的可选值(鼠标的各种样式)
- #481 – 在InkCanvas 上使用鼠标绘图(You Can Draw On an InkCanvas Control with the Mouse)
- 比较全的CSS cursor(鼠标样式)
- 比较全的CSS cursor(鼠标样式)
- 网页鼠标指针样式(cursor属性)
- cursor -- 定义鼠标样式
- style cursor 鼠标样式
- 解决RadioGroup setOnCheckedChangedListener多次调用
- play框架的问题探讨
- linux find命令用法
- Qt语言家使用问题:在语言家翻译了,但程序起来翻译就是不起作用
- 分享一个超强的连接Ubuntu ssh 工具
- #711 – 在拖拽的过程中改变鼠标样式(Changing the Mouse Cursor While Dragging)
- js多图片上传--一次性上传多张
- Array.asList():数组转list时你一定要知道的“陷阱”!
- 数据库视图
- Android复制功能
- kettle大全
- 杭电ACM2022:海选女主角
- Python处理excel基本操作
- window与ubuntu使用cuteftp文件互传出现权限问题