WPF - Canvas.GetTop returns NeuN

I'm trying to get the position of the 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 would say this is not a scale issue because SetTop works great.

Any ideas? Thanks in advance:)

-1


a source to share


1 answer


Ok I found a workaround. I would still evaluate alternatives in case anyone has a better way to do this.

Basically, since 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);

      

+1


a source







All Articles