0
我想創建一個listview,其中包含一些項目。 每個項目都有一個特定的大小(全部相同)並且可點擊。如何在一行上的ListView上停止溢出
我已經創建了列表視圖,但是一旦達到了列表視圖的最大寬度尺寸,它就會換行並進入第二行。我想有一個水平滾動條和我的所有項目在一行上。
對於爲例,我有5個項目,但它顯示:
我想有水平滾動條可以看到第五。
這裏是我的XAML代碼:
<ListView Background="#1A1A1A" HorizontalAlignment="Stretch" Margin="10,0,10,0" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Auto" Height="100" ItemsSource="{Binding Projects}" SelectionChanged="ListView_SelectionChanged">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
ItemHeight="{Binding (ListView.View).ItemHeight, RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="#CCCCCC" BorderThickness="1">
<StackPanel Orientation="Horizontal" Height="100" Width="200">
<TextBlock Height="100" Width="200" FontSize="20" Padding="0,25,0,0" TextAlignment="Center" Foreground="#1A1A1A" Background="{Binding BackgroundColor}" Text="{Binding Title}" />
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
剛剛有了一個快速瀏覽一下,你肯定ü要WrapPanel? – Muds
我可以改變這一點,至於它做什麼,我需要:) – carndacier
使它堆疊面板,看到它它使任何差異 – Muds