views:

400

answers:

2

Hi,

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

A: 

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
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
+1  A: 

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