0

I have an InkCanvas which has it's children programmically added in through C#. They are not set with InkCanvas.LeftProperty or InkCanvas.TopProperty. I was wondering if it was at all possible to get these default X and Y values of the elements. Currently if I check the InkCanvas.LeftProperty or InkCanvas.TopProperty it would return NaN as they are not set. Is this possible at all? Thanks in advance for any help.

Cheers,

Nilu

Nilu
  • 245
  • 1
  • 4
  • 17

2 Answers2

3

I think this might be the answer:

Vector vector = VisualTreeHelper.GetOffset(element);

It returns a vector with the element offset relative to the parent. More information can be found here.

Edit: Don't think this is going to help me for what I want to do. Although it's a good method if you are setting the margin on elements initially. In my case I think I would have to set the co-ordinates explicitly.

Nilu
  • 245
  • 1
  • 4
  • 17
0

You want to use various static methods defined on Canvas to get those values - GetLeft(), GetTop(), etc. I believe that LeftProperty is just the definition of the attached property itself, not the way to get the value.

Andy
  • 30,088
  • 6
  • 78
  • 89
  • Yes, you are right. However even when I used those methods the values are NaN. However I was able to find the VisualTreeHelper method which would return the offset of the element relative to the parent (InkCanvas). Which seems to work atm. Thanks for your help. :) – Nilu Sep 21 '09 at 00:39