Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find control position on canvas

I have a Canvas which contains a few Textblocks and I need to find the top and left corner points that were assigned in the XAML Document. How can I get those two properties?

When I loop through the Framework Elements on the Canvas I can't seem to find those to properties listed.

like image 910
user337816 Avatar asked Jul 22 '10 20:07

user337816


1 Answers

Here some examples how to get the values:

foreach(FrameworkElement fe in canvas.Children){

   // example 0
   double top=(double)fe.GetValue(Canvas.TopProperty);
   double left=(double)fe.GetValue(Canvas.LeftProperty);

   // example 1
   double top1=Canvas.GetTop(fe);
   double left1=Canvas.GetLeft(fe);

}

See http://msdn.microsoft.com/en-us/library/ms749011.aspx and http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.top.aspx for more information

like image 119
HCL Avatar answered Nov 15 '22 22:11

HCL