Canvas.Left和Canvas.Top的Setter在WPF中是readwrite,但在Silverlight 4中不是,为什么?
我有以下XAML,它在WPF中运行良好,但在Silverlight4中不起作用Canvas.Left和Canvas.Top的Setter在WPF中是readwrite,但在Silverlight 4中不是,为什么?,wpf,silverlight,data-binding,styles,setter,Wpf,Silverlight,Data Binding,Styles,Setter,我有以下XAML,它在WPF中运行良好,但在Silverlight4中不起作用 <ItemsPanelTemplate x:Key="ContentListBoxItemsPanelTemplate"> <Canvas/> </ItemsPanelTemplate> <DataTemplate x:Key="ContentListBoxItemTemplate">
<ItemsPanelTemplate x:Key="ContentListBoxItemsPanelTemplate">
<Canvas/>
</ItemsPanelTemplate>
<DataTemplate x:Key="ContentListBoxItemTemplate">
<Border CornerRadius="15" Width="150" Margin="3" Height="300">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="OrangeRed" Offset="1" />
<GradientStop Color="Brown" Offset="0" />
</LinearGradientBrush>
</Border.Background>
</Border>
</DataTemplate>
<Style TargetType="ListBoxItem">
<Setter Property="Canvas.Left" Value="{Binding Left}"/>
<Setter Property="Canvas.Top" Value="{Binding Top}"/>
</Style>
然后在某个地方:
<ListBox Name="ContentList"
ItemTemplate="{StaticResource ContentListBoxItemTemplate}"
ItemsPanel="{StaticResource ContentListBoxItemsPanelTemplate}" />
如果我在Silverlight中尝试同样的事情,我会得到一个异常,即setter无法设置只读属性,但我仍然希望在Silverlight中不使用代码实现同样的事情
有什么建议吗?Silverlight不支持setter值中的绑定。David Anson在这里有一个很好的解决方法:我喜欢这个链接,但这给了我:无法访问“ListBoxItem”类型上的DependencyProperty“Canvas.Top”。由SetterValueBindingHelper类抛出,似乎我忘记了类型参数。但它仍然不能100%工作,只有最后一个setter可以工作。。。联系作者,如果他能解决这个问题,当然我会将你的答案标记为解决方案这里有一个更新版本可以解决这个问题