开发者

Setter for Canvas.Left and Canvas.Top readwrite in WPF but not in Silverlight 4, why?

I have the following XAML, which works fine in WPF, but not in Silverlight 4

       <ItemsPanelTemplate x:Key="ContentListBoxItemsPanelTemplate">
            <Canvas/>
        </ItemsPanelTemplate>

        <DataTemplate x:Key="ContentListBoxItemTemplate">
            <Border CornerRadius="15" Width="150" Margin="3" He开发者_如何学编程ight="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>

And then somewhere:

 <ListBox Name="ContentList" 
          ItemTemplate="{StaticResource ContentListBoxItemTemplate}"
          ItemsPanel="{StaticResource ContentListBoxItemsPanelTemplate}" />

If I try the same thing in Silverlight I get an exception saying that the setter cannot set a read only property, but I still want to achieve the same thing in Silverlight without code.

Any suggestions?


Silverlight does not support bindings in the value of the setter. David Anson has a great workaround here: http://blogs.msdn.com/delay/archive/2009/05/07/one-more-platform-difference-more-or-less-tamed-settervaluebindinghelper-makes-silverlight-setters-better.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜