WPF水平列表框垂直填充
问题描述:
我正在制作一个显示在水平滚动的列表框中的产品列表。我有列表水平滚动,但我只获得1行的项目,即使列表框高到足以填充2行,然后开始水平滚动。WPF水平列表框垂直填充
我的WPF代码的一部分。
<DataTemplate x:Key="productTemplate">
<WrapPanel Orientation="Horizontal" Width="10" Height="10">
<Image Source="{Binding Photo}" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center" Width="288" Height="320"/>
<Label Content="{Binding Name}" />
<Label Content="{Binding Cost}" />
</WrapPanel>
</DataTemplate>
<ListBox Width="1334" ItemsSource="{Binding Products}" SelectedItem="{Binding SelectedProduct}" ItemTemplate="{DynamicResource productTemplate}" Height="865" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Disabled" BorderThickness="0">
<ListBox.Background>
<SolidColorBrush Color="White" Opacity="0.85"/>
</ListBox.Background>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
我在寻找:
任何帮助将是巨大的。
答
被用作ItemsPanel必须垂直方向,并列表框不能垂直滚动WrapPanel:
<ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled" ...>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
...
</ListBox>
答
也许下面的代码将帮助你。以下代码将帮助您按以下方式绑定图像。
<ListBox Grid.Column="1" ItemsSource="{Binding Items}" Name="detailList" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"></WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Width="90">
<Image Width="80" Source="{Binding Type,
Converter={x:Static local:HeaderToImageConverter.Instance}}"/>
<TextBlock FontSize="11" Text="{Binding Name}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
妈逮到它,我是如此接近尝试此¬¬干杯(Y) – Sjc311