views:

454

answers:

1

Hi,

I'm trying to get the position of a canvas from a mouse move handler but it returns NeuN.

The canvas is inside another canvas and the code is:

Console.WriteLine(Canvas.GetTop(canvas2));

this is inside:

private void move(object sender, MouseEventArgs e)
{
Console.WriteLine(Canvas.GetTop(canvas2));
}

I'd say it can't be a scope problem because as SetTop works fine.

Any ideas? Thanks in advance :)

A: 

Ok, I found a workaround. I'd still appreciate alternatives if somebody has a better way of doing this.

Basically, as GetTop doesn't work I thought I could get the RenderTransform object. And it worked!

canvas2.RenderTransform.Value.OffsetY

Thanks.

EDIT: You can also do this:

Double current_y = (double)this.GetValue(Canvas.TopProperty);
ozke