Hello,
The following code works perfectly:
A very simple Silverlight application with a Canvas, two children, an image and a rectangle.
This is the Xaml:
<UserControl x:Class="SilverlightApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<Canvas Height="163" HorizontalAlignment="Left" Margin="54,69,0,0" Name="canvas1" VerticalAlignment="Top" Width="286">
<Image Canvas.Left="30" Canvas.Top="25" Height="91" Name="image1" Stretch="Fill" Width="116" Source="/SilverlightApplication2;component/Images/diplodocus2.jpg" />
<Rectangle Canvas.Left="186" Canvas.Top="68" Height="69" Name="rectangle1" Stroke="Black" StrokeThickness="1" Width="94" />
</Canvas>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="208,259,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</UserControl>
Ans this is the code behind:
private void button1_Click(object sender, RoutedEventArgs e)
{
foreach (var item in this.canvas1.Children)
{
double X = Canvas.GetLeft((UIElement)item);
}
}
When the code executes Canvas.GetLeft returns the correct values.
Hope it helps.
Valery.