我有一个装饰边框的装饰器(请参见下面的屏幕截图)。但是,仅在单击装饰器中的元素时才会引发装饰器的 MouseDown 事件。当单击装饰元素上方的装饰器中的任何位置时,我需要引发 MouseDown 事件。如何才能做到这一点?我必须在装饰器中添加透明控件还是有其他方法?谢谢你的帮助!
屏幕截图和 VS 2008 项目:http ://cid-0432ee4cfe9c26a0.skydrive.live.com/browse.aspx/%C3%96ffentlich?uc=2
装饰者守则:
class myAdorner : Adorner
{
public myAdorner(UIElement element)
: base(element)
{
this.MouseDown += new System.Windows.Input.MouseButtonEventHandler(myAdorner_MouseDown);
}
void myAdorner_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MessageBox.Show("ok");
}
// Draws two rectangles: one in the upper-left and another one in the lower-right corner
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
{
Size size = this.AdornedElement.RenderSize;
Rect r1 = new Rect(0.5, 0.5, 20, 20);
Rect r4 = new Rect(size.Width - 20.5, size.Height - 20.5, 20, 20);
SolidColorBrush brush = new SolidColorBrush(Colors.AliceBlue);
Pen pen = new Pen(Brushes.Black, 1);
drawingContext.DrawRectangle(brush, pen, r1);
drawingContext.DrawRectangle(brush, pen, r4);
}
}