Silverlight 4.0 Silverlight 4:是否可以绑定ListBoxItem';s的宽度和高度属性?

Silverlight 4.0 Silverlight 4:是否可以绑定ListBoxItem';s的宽度和高度属性?,silverlight-4.0,Silverlight 4.0,我有以下问题: 我有一个列表框,里面的项目都放在画布上。我希望能够准确地定位它的元素。ItemContainerStyle如下所示: <Style x:Key="ElementContainerStyle" TargetType="ListBoxItem" > <Setter Property="Canvas.Top" Value="{Binding BoundingBox.Y}" /> <Setter Property="Canvas.Left" Valu

我有以下问题:

我有一个列表框,里面的项目都放在画布上。我希望能够准确地定位它的元素。ItemContainerStyle如下所示:

<Style x:Key="ElementContainerStyle" TargetType="ListBoxItem" >
  <Setter Property="Canvas.Top" Value="{Binding BoundingBox.Y}" />
  <Setter Property="Canvas.Left" Value="{Binding BoundingBox.X}" />
  <Setter Property="Width" Value="{Binding BoundingBox.Width}" />
  <Setter Property="Height" Value="{Binding BoundingBox.Height}" />
  ...
</Style>

...
使用这种样式,SL会崩溃,并显示InnerException的消息:

System.NotSupportedException:无法设置只读属性

为什么是只读属性?如果我把正则值放在那里(没有数据限制),它运行得很好,除了-这不是我想要的

我很期待SL4的新功能(比如绑定到宽度和高度属性的能力),但似乎这样的技巧仍然无法实现

它在WPF中运行良好


有人能解释一下吗

Silverlight不支持将绑定分配给Setter.Value属性。请查看此解决方法,该方法在将样式应用于实例时使用附着的属性创建/指定绑定