0

に複数の列を指定したいのですListBoxが、グーグルのスキルで失敗しました。

ItemsPanelTemplateのを変更して、ListBox表示される列をカスタマイズするにはどうすればよいですか?

編集:私がすでに試したものを置くのを忘れた

私はコードを試しました

<ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
        <UniformGrid Columns="3" />
    </ItemsPanelTemplate>

垂直スクロールバーを失う以外は機能します

4

2 に答える 2

0

それほど難しいことではありませんが、状況によって異なります。項目ごとにグリッドまたはそのようなコントロールを使用していて、列が可変幅の項目と同じ幅でなくてもかまわない場合は、グリッドを追加するだけです。 ItemTemplate にします。

<ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition>
                <ColumnDefinition>
                <ColumnDefinition>
            </Grid.ColumnDefinitions>
            <SomeControl Grid.Column="0" />
            <SomeControl Grid.Column="1" />
            <SomeControl Grid.Column="2" />
        </Grid>
    </DataTemplate>
</ItemTemplate>

唯一の問題は、グリッド列を可変サイズのコンテンツですべて同じサイズにしたい場合です。この場合、もう少し複雑になります。それ以外の場合は、明示的にサイズを設定するか、設定によってコンテンツにサイズを決定させることができます。列幅を に変更し"Auto"ます。

于 2012-07-11T16:00:23.663 に答える
0

これは、3 列、アイテムの折り返し、および周囲のレイアウトに応じて機能する自動垂直スクロールを備えた、あなたが探していると思われるものの簡単な例です。

<ListBox HorizontalContentAlignment="Stretch">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="3"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Border MinHeight="150" Margin="5" Background="Green" CornerRadius="4">
                <TextBlock Text="{Binding}" Foreground="White"/>
            </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>

    <System:String>One</System:String>
    <System:String>Two</System:String>
    <System:String>Three</System:String>
    <System:String>Four</System:String>
    <System:String>Five</System:String>
    <System:String>Six</System:String>
    <System:String>Seven</System:String>
    <System:String>Eight</System:String>
    <System:String>Nine</System:String>
    <System:String>Ten</System:String>
</ListBox>
于 2012-07-11T19:14:03.180 に答える