0

ItemsSource が文字列のコレクションである ListView があります。ご想像のとおり、文字列のコレクションはさまざまな長さです。私の目標は、これらの文字列を listView に水平に表示することです。

ListView を水平に使用する例はたくさんあるので、その部分は簡単でした。Horizo​​ntal StackPanel を ItemsPanelTemplate として指定することでそれを達成しました...

私のListView xaml:

 <ListView x:Name="myListView">
  <ListView.ItemsPanel>
    <ItemsPanelTemplate>
      <StackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
  </ListView.ItemsPanel>
  <ListView.View>
    <GridView>
      <GridViewColumn>
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <StackPanel Orientation="Horizontal">
              <Button Click="Button_Click" FontSize="10" Foreground="Salmon"  BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Content="x" Background="Transparent" />
              <Label FontSize="10" Foreground="SteelBlue" Content="{Binding}"/>
            </StackPanel>
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
    </GridView>
  </ListView.View>
</ListView>

私が表示しようとしているもの:

[This is a string] [This is also a string] [abc] [Look at me]

私のxamlが表示するもの:

[This i] [This i] [abc   ] [Look a]

GridviewColumn に幅を設定すると、次のようになります。

[This is a string  ][This is also a string] [abc           ][Look at me        ]

[列の幅] を [自動] に設定すると、最も幅の広いアイテムと同じ大きさになります... しかし、スペースを節約して実際の幅で並べて配置したいと思います。

私は成功せずに多くの研究を行ってきましたが、何かアイデアはありますか?

4

1 に答える 1