I'm currently trying to snap a collection of objects to a canvas in Silverlight 3 using the ItemsControl element, as shown 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 that binding to Canvas.Left is ignored. From what I learned here , it seems that this is due to the fact that the elements are placed inside the media presenter, and not the actual canvas that I specified in the panel elements.
Can I use data binding to determine the position of elements on a canvas?
source
share