如何在ListView中设置图像的大小?
目标设备是Windows Phone 10(即Windows通用平台).
我发现了以下文档:
请注意,在定位Windows Phone 8.1时,ImageCell默认情况下不会缩放图像.此外,请注意,Windows Phone 8.1是唯一一个默认情况下,详细文本以与主文本相同的颜色和字体显示的平台.Windows Phone 8.0呈现ImageCell,如下所示:
我试过了:
<ListView Grid.Row="1" ItemsSource="{Binding Photos}" SelectedItem="{Binding SelectedPhoto, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell ImageSource="{Binding ImageSource}" Text="{Binding Description}" TextColor="Silver" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
上图显示了完整的图像,没有限制图像的大小以适合作为列表视图项目.
我也尝试过:
<ListView Grid.Row="1" ItemsSource="{Binding Photos}" SelectedItem="{Binding SelectedPhoto, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageSource}" Aspect="AspectFit" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
上面的代码没有显示任何图像.它只显示一个白色背景.
一些事情:-
ImageCell
无法指定图像宽度/高度(v2.0.x).
你的第二个例子更加正常,但是,你需要将它包装成一个ViewCell
像你所处理的ListView
那样: -
<ListView ItemsSource="{Binding Photos}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Image Source="{Binding MyImage}" Aspect="AspectFit" WidthRequest="{Binding MyWidth}" HeightRequest="{Binding MyHeight}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Run Code Online (Sandbox Code Playgroud)
另请注意,a的默认值ListView
设置为具有相等的行高.
因此,如果您有不同的图像大小,可能无法产生您想要的输出.
要解决此问题,请指定HasUnevenRows='True'
.
如果你进一步做BindableProperties
你想要的ImageWidth
和你的想法,并ImageHeight
在ViewModel
上面的例子中指定它们使用WidthRequest
和HeightRequest
为Image
你在指定不同的值时得到类似的输出: -
归档时间: |
|
查看次数: |
9891 次 |
最近记录: |