WPF在InkCanvas中的绝对定位

时间:2009-09-10 04:04:21

标签: wpf css-position inkcanvas

我正在尝试在InkCanvas中放置一个矩形。我使用以下方法。不幸的是,当我添加矩形时,它会显示在(0,0)。虽然当我查询左侧属性是否为0时,我得到非零值。有谁知道为什么会这样?

干杯,

尼鲁

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

1 个答案:

答案 0 :(得分:4)

终于能搞清楚了。我也觉得有点傻。而不是Canvas.SetTop()需要使用InkCanvas.SetTop