开发者

Silverlight 4: Is it possible to bind ListBoxItem's width and height property?

I've got following issue:

I've got a ListBox which items are lain on Canvas. I would like to be able to xamly position its elements. The ItemContainerStyle looks like this:

<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>

With such a style SL crashes with InnerException's message:

System.NotSupportedException: Cannot set read-only property

Why's that read-only property? If I put regular values there (not data bounded) it runs well, except - this is not what I wanted.

I was looking forward to new features for SL4 (like ability to bind to Width and Height properties), but it seems that such a trick still can't be done?

It works fine in WPF..

Anyone can s开发者_StackOverflowhed some light on this?


Assigning a Binding to the Setter.Value property is not supported in Silverlight. Check out this blog post for a workaround, which uses an attached property to create/assign the binding when the Style is applied to an instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜