【问题标题】:Silverlight 4: Is it possible to bind ListBoxItem's width and height property?Silverlight 4:是否可以绑定 ListBoxItem 的宽度和高度属性?
【发布时间】:2010-08-24 01:24:16
【问题描述】:

我有以下问题:

我有一个列表框,其中项目位于 Canvas 上。我希望能够 xamly 定位它的元素。 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 的新功能(比如绑定到 Width 和 Height 属性的能力),但似乎这样的技巧仍然无法完成?

它在 WPF 中运行良好..

任何人都可以对此有所了解吗?

【问题讨论】:

    标签: silverlight-4.0


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多