1
它似乎適用於所有人,但不適合我。我想在我的窗口較大時用水平填充ListView項目,然後用項目堆疊面板。我有以下的.xaml填寫WPF中的ListView項目
<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>
目前還不清楚你的實際問題是什麼。你想要物品均勻地填充StackPanel,還是隻需要最後一個物品填充重新渲染空間? – Clemens
如果窗口較大,我希望物品均勻地填充StackPanel –
@AshotKhachatryan。如果窗戶更小,該怎麼辦? – dkozl