我向WPF画布添加一堆矩形,如下所示:
Rectangle rectangle = new Rectangle
{
Width = tuple.Width,
Height = tuple.Height,
Stroke = Brushes.Black,
StrokeThickness = 1
};
rectangle.MouseEnter += (s, e) => rectangle.Stroke = Brushes.Gray;
rectangle.MouseLeave += (s, e) => rectangle.Stroke = Brushes.Black;
Canvas.SetLeft(rectangle, tuple.X);
Canvas.SetTop(rectangle, tuple.Y);
canvas.Children.Add(rectangle);
我期望什么:
实际发生的事情:
那为什么呢?如何实现预期的行为?
答案 0 :(得分:0)
如果给矩形填充,一切都会按预期进行:
Rectangle rectangle = new Rectangle
{
Width = tuple.Width,
Height = tuple.Height,
Stroke = Brushes.DarkGray,
StrokeThickness = 1,
Fill = Brushes.Transparent
};