Silverlight 3 - Data Binding Position of a rectangle on a canvas

Posted by Blounty on Stack Overflow See other posts from Stack Overflow or by Blounty
Published on 2009-10-28T13:53:59Z Indexed on 2010/03/14 22:25 UTC
Read the original article Hit count: 523

Hi Everyone,

I am currently trying to bind a collection of objects to a Canvas in Silverlight 3 using an ItemsControl as below:

<ItemsControl x:Name="ctrl" ItemsSource="{Binding myObjectsCollection}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas></Canvas>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Rectangle Stroke="LightGray" Fill="Black"  StrokeThickness="2" 
                   RadiusX="15" RadiusY="15" Canvas.Left="{Binding XAxis}"
                   Height="25" Width="25">
            </Rectangle>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Unfortunately it seems the binding on the Canvas.Left is being ignored. From what i have learned here it would appear this is due to the items being placed inside a content presenter not the actual canvas i have specified in the items panel.

Is there a way i can use data binding to determine the position of elements on a canvas?

© Stack Overflow or respective owner

Related posts about silverlight-2.0

Related posts about silverlight-3.0