开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜