代码之家  ›  专栏  ›  技术社区  ›  TimothyP

Canvas.Left和Canvas.TopReadWrite的setter在WPF中,但在Silverlight4中没有,为什么?

  •  1
  • TimothyP  · 技术社区  · 14 年前

    我有以下XAML,它在WPF中可以正常工作,但在Silverlight4中不行

           <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中实现相同的操作,而不需要代码。

    有什么建议吗?

    1 回复  |  直到 14 年前
        1
  •  3
  •   Jeremiah Morrill    14 年前