3

WPF では、Canvas を ItemsPanel として ListBox を作成し、そのキャンバスに項目を配置できます。これを行うコードは次のようになります。

<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 の ListBox または ItemsControl で同じことができますか?

4

1 に答える 1