2

I'm trying to position a rectangle in an InkCanvas. I am using the following method. Unfortunately when I add the rectangle it gets displayed at (0,0). Although when I query to see the whether the left property is 0 I get a non zero values. Does anyone know why this might be?

Cheers,

Nilu

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);            
    }
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Nilu
  • 245
  • 1
  • 4
  • 17

1 Answers1

4

Finally able to figure out. I feel kinda stupid too. Instead of Canvas.SetTop() need to use InkCanvas.SetTop.

Nilu
  • 245
  • 1
  • 4
  • 17