【发布时间】:2011-03-06 13:01:32
【问题描述】:
我正在尝试将应用程序从 WPF 移植到 Silverlight,但它在一些非常简单的绑定上失败了。
我有以下简单的例子:
<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>
但是,Silverlight 解析会崩溃。 但是,如果我将绑定替换为常量,则一切正常:
<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>
这是为什么?
【问题讨论】:
标签: silverlight data-binding silverlight-4.0