您好我想在点击它们后使我的图形对象“选中”。
我尝试了类似的东西来制作选定的行:
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#。
答案 0 :(得分:1)
您可以使用Adorners将形状显示为“已选中”,这样您也可以在XAML中进行“选定”状态视觉提示。
您可以使用Attached Property向对象“添加”IsSelected
属性(例如布尔值),并在每次点击事件上升时切换值。