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