它似乎适合所有人,但不适合我。我希望在窗口较大时水平填充ListView项目,然后使用项目堆叠面板。我有以下.xaml
<ListView x:Name="comboBox" ItemsSource="{Binding ArticleCategories}" SelectedItem="{Binding SelectedArticleCategory}" HorizontalAlignment="Stretch" Margin="0,0,0,0" Background="Azure" VerticalAlignment="Top">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" ></Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Button Content="abc" Width="Auto"></Button>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 0 :(得分:1)
您可以将一行UniformGrid
用作ItemsPanel
:
<ListView ...>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Button Content="abc"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>