2
我试图在InkCanvas
中定位一个矩形。我正在使用以下方法。不幸的是,当我添加矩形时,它显示在(0,0)
。虽然当我查询左边属性是否为0
时,我得到一个非零值。有谁知道这可能是为什么?WPF在InkCanvas中的绝对定位
干杯,
尼鲁
InkCanvas _parent = new InkCanvas();
private void AddDisplayRect(Color annoColour, Rect bounds)
{
Rectangle displayRect = new Rectangle();
Canvas.SetTop(displayRect, bounds.Y);
Canvas.SetLeft(displayRect, bounds.X);
// check to see if the property is set
Trace.WriteLine(Canvas.GetLeft(displayRect));
displayRect.Width = bounds.Width;
displayRect.Height = bounds.Height;
displayRect.Stroke = new SolidColorBrush(annoColour);
displayRect.StrokeThickness = 1;
_parent.Children.Add(displayRect);
}