How can I place element to position with Silverlight?
I want to draw rectangle to position what I get from startPoint, but now it places my recta开发者_StackOverflow社区ngle to middle of PictureCanvas, when I want to put it in startPoint position
private void DragSelectComponent_SelectionEnd(DragSelectEventArgs e)
{
Output.Text = "Start: " + e.StartPoint.ToString() + " End: " + e.EndPoint.ToString() + "\n(" + e.EventType + ")\n";
Rectangle rectangle = new Rectangle() { Width = e.EndPoint.X - e.StartPoint.X, Height = e.EndPoint.Y - e.StartPoint.Y, Fill = new SolidColorBrush(Colors.Purple) };
PictureCanvas.Children.Add(rectangle);
}
Just use:-
Rectangle rectangle = new Rectangle() { Width = e.EndPoint.X - e.StartPoint.X, Height = e.EndPoint.Y - e.StartPoint.Y, Fill = new SolidColorBrush(Colors.Purple) };
Canvas.SetLeft(rectangle, e.StartPoint.X);
Canvas.SetTop(rectangle, e.StartPoint.Y);
PictureCanvas.Children.Add(rectangle);
Have you tried:
rectangle.SetValue(Canvas.LeftProperty, p.X);
rectangle.SetValue(Canvas.TopProperty, p.Y);
精彩评论