在 WPF 中拖动选择框 [英] Drag selection box in WPF
本文介绍了在 WPF 中拖动选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
WPF中是否可以通过将鼠标悬停在对象上并绘制一个圆圈并拖动选择悬停框来实现鼠标悬停选择.当用户通过画一个圆圈将鼠标悬停在按钮 a 上时,我特别想要什么,这个按钮会做出特定的动作,比如点击它.能否提供一些示例代码或链接?
Is it possible to implement mouse hover selection by hover on the object and drawing a circle and drag selection hover box in WPF. what I want specifically when the user hover on the button a by drawing a circle this button make specific action like as click on it. Could you give a bit of sample code or a link?
推荐答案
属于高级话题,涉及到装饰器的使用更多信息可以在这里找到:
It is an advanced topic and involves the use of adorners More information can be found here :
和
我使用它的一个小例子:
A small example where I used it :
public class SelectionAdorner : Adorner
{
public SelectionAdorner(UIElement adornedElement)
: base(adornedElement)
{
}
protected override void OnRender(DrawingContext drawingContext)
{
Rect adornedElementRect = new Rect(0,0,ActualWidth,ActualHeight);
// Some arbitrary drawing implements.
SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green);
renderBrush.Opacity = 0.2;
Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
double renderRadius = 5.0;
// Draw a circle at each corner.
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopLeft, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.TopRight, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomLeft, renderRadius, renderRadius);
drawingContext.DrawEllipse(renderBrush, renderPen, adornedElementRect.BottomRight, renderRadius, renderRadius);
}
}
这篇关于在 WPF 中拖动选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文