问题
I am trying to port an application from WPF to Silverlight but it fails on some very simple binding.
I have the following simple example:
<ListBox >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Canvas.Top" Value="{Binding X}"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas></Canvas>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
However, Silverlight parsing crashes. However, if I replace the binding with a constant, things are OK:
<ListBox >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Canvas.Top" Value="3"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas></Canvas>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Why is this?
回答1:
You can try this workaround:
http://blogs.msdn.com/delay/archive/2009/11/02/as-the-platform-evolves-so-do-the-workarounds-better-settervaluebindinghelper-makes-silverlight-setters-better-er.aspx
回答2:
Nop it doesn't provide that (still)
来源:https://stackoverflow.com/questions/3088644/does-silverlight-4-0-support-bindings-in-a-style-setter