Hi i want to make my graphic object "selected" after click on them.
I tryied something like that to make selected line:
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);
}
Its a bit stupid, and its hard to make white rectangle with distance from line. Is there any good way to do this without tons of if() ?
Im using VS2012, WPF/C# .
You can use Adorners to show your shape as "selected", this way you can also make the "selected" state visual hint in XAML.
And you can use an Attached Property to "add" a IsSelected property (boolean for example) to your object and toggle the value each time there is a click event rised.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With