【发布时间】:2016-10-02 04:02:26
【问题描述】:
我正在尝试制作一个列表视图,其中每个项目都是一个图像。我希望列表视图水平显示项目。如果视图框项目不能水平放置在窗口中,我想要一个水平滚动条。如果列表项不能垂直适合窗口,我希望图像按比例缩小以使其适合。我似乎在列表视图上获得了一个垂直滚动条,而不是缩放图像以适应。
当窗口垂直调整大小时,它会导致垂直滚动条出现在列表视图上。我尝试了各种将图像高度设置为祖先列表视图高度的选项,但我无法使其正常工作。如何实现我想要的行为?
<Window x:Class="ViewBoxExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ViewBoxExample"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:MainWindow}"
Title="Viewbox Test"
Height="400" Width="600">
<Window.Resources>
<DataTemplate x:Key="ItemTemplate" >
<Border BorderBrush="Black" BorderThickness="2" >
<Image Margin="2" Source="image.png" />
</Border>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListView VerticalAlignment="Stretch"
ItemTemplate="{StaticResource ItemTemplate}"
ItemsSource="{Binding Items}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
</StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
<Grid Grid.Row="1" Height="100">
<!--placeholder for more content-->
</Grid>
</Grid>
</Window>
【问题讨论】: