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