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

如何使用Silverlight2项目控件在画布上定位项目集合?

  •  3
  • geofftnz  · 技术社区  · 15 年前

    在wpf中,可以创建一个将画布作为itemspanel的列表框,并在该画布上放置项。执行此操作的代码如下所示:

    <ListBox ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Path=Name}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas Width="200" Height="200"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="Canvas.Left" Value="{Binding Path=XPos}"/>
                <Setter Property="Canvas.Top" Value="{Binding Path=YPos}"/>
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>
    

    你能在silverlight2列表框或itemscontrol中做同样的事情吗?

    1 回复  |  直到 15 年前
        1
  •  2
  •   geofftnz    15 年前

    我找到了 解决方案,但(对我)它闻起来。

    <ListBox ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Canvas Width="200" Height="200">
                    <TextBlock 
                        Text="{Binding Path=Name}" 
                        Canvas.Left="{Binding Path=XPos}" 
                        Canvas.Top="{Binding Path=YPos}" />
                </Canvas>
            </DataTemplate>
        </ListBox.ItemTemplate>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas Width="200" Height="200"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>
    

    每件物品都有自己的画布,所以它们最终会堆叠在一起。