嗨,我想让我的图形对象在单击它们后“被选中”。
我尝试了类似的方法来制作选定的行:
else if (e.OriginalSource is Line)
{
LineFocus = true;
MojaLinia = (Line)e.OriginalSource;
Rectangle rect_1 = new Rectangle
{
Stroke = Brushes.Black,
StrokeThickness = 1,
Fill = new SolidColorBrush(Color.FromRgb(255, 255, 255))
};
rect_1.Width = 6;
rect_1.Height = 6;
Canvas.SetLeft(rect_1, MojaLinia.X1);
Canvas.SetTop(rect_1, MojaLinia.Y1);
canvas.Children.Add(rect_1);
Rectangle rect_2 = new Rectangle
{
Stroke = Brushes.Black,
StrokeThickness = 1,
Fill = new SolidColorBrush(Color.FromRgb(255, 255, 255))
};
rect_2.Width = 6;
rect_2.Height = 6;
Canvas.SetLeft(rect_2, MojaLinia.X2);
Canvas.SetTop(rect_2, MojaLinia.Y2);
canvas.Children.Add(rect_2);
}
它有点愚蠢,并且很难制作与线有距离的白色矩形。没有大量的 if() 有什么好的方法吗?
我正在使用 VS2012,WPF/C#。