【发布时间】:2009-10-28 13:53:59
【问题描述】:
我目前正在尝试使用 ItemsControl 将对象集合绑定到 Silverlight 3 中的 Canvas,如下所示:
<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>
不幸的是,Canvas.Left 上的绑定似乎被忽略了。从我了解到的here 看来,这是由于项目被放置在内容演示器中,而不是我在项目面板中指定的实际画布。
有没有一种方法可以使用数据绑定来确定画布上元素的位置?
【问题讨论】:
标签: c# data-binding silverlight-3.0 silverlight-2.0