Q:

Getting the location of a Grid during runtime in codebehind

I am in the codebehind file for a usercontrol.  In this user control I have a grid called GBoard.  I create one instance of this user control in my main XAML file and I name it GameBoard.  Now I am in the codebehind as I said earlier, and I want to get the X/Y position of GameBoard.  If I grab the Margin, all the values are set to 0.  If I do Canvas.GetTop(this) it comes back as NaN.  How do I grab these coordinates?  I don't think it's a bug in my code as everything works, its just I can't seem to grab the coordinates.  
Position = new Point(Canvas.GetTop(GameBoard), Canvas.GetLeft(GameBoard));

gets NaN for values.  
boardMargin = GameBoard.Margin;  

boardMargin is 0,0,0,0 even though its positioned in the center of the screen.  
<UserControl x:Class="UserControls.Board"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         xmlns:controls="clr-namespace:UserControls"
         d:DesignHeight="300" d:DesignWidth="300">

    <Grid Name="GBoard">
        <Grid.ColumnDefinitions>
            //lots of these
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            //lots of these
        </Grid.RowDefinitions>
    </Grid>
</UserControl>

that's the user control.  I edited out the massive amount of col and row defs for space.  
<Page x:Class="GUI.SGUI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="clr-namespace:UserControls"
  Title="SGUI" Height="1000" Width="1000">

    <Canvas x:Name="LetterCanvas">
        <controls:Board x:Name="GameBoard" Height="Auto" Canvas.Left="120" Canvas.Top="164" Width="Auto"/>
    </Canvas>
</Page>

I found out that if I access the location from the main class then I can get the coordinates, if I access them from the user control's codebehind I can't.  So if I have to I can make something hacky, but I'd rather get the coordinates inside of the user control.  

A:

The code in your usercontrol needs access to the Canvas in order to get the GameBoard's position because the Canvas element in WPF uses absolute positioning.
Assuming that LetterCanvas will be the parent element of the GameBoard - try using this in the code behind for your GameBoard user control: 
double xPosition = Canvas.GetLeft(this);
double yPosition = Canvas.GetTop(this);

NOTE: must call from method and not constructor.  

