我想以类似于列表模式下的WinForms ListView的方式在ListView中布置项目.也就是说,在ListView中不仅在垂直方向而且在水平方向上布置项目.
我不介意这些物品的布局是这样的:
1 4 7
2 5 8
3 6 9
或者像这样:
1 2 3
4 5 6
7 8 9
只要它们在垂直和水平方向呈现,以便最大限度地利用可用空间.
我能找到的最接近的是这个问题:
只能水平放置项目.
我试图在ListView中显示一些图像,但没有成功.我正在使用WPF MVVM,而ListView是简单地显示套装和排名数据的延续.(请参阅我之前的帖子:WPF中的MVVM - 如何提醒ViewModel模型中的更改......或者我应该?如果您感兴趣的话!)也就是说,我可以使用ListView以外的东西(如果这是建议)但我仍然想知道如何使用ListView,假设它是可行的.我在ViewModel中绑定的属性是:
public ObservableCollection<Image> PlayerCardImages{
get{
ObservableCollection<Image> results = new ObservableCollection<Image>();
foreach (CardModel card in PlayerCards)
{
Image img = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.BeginInit();
// TODO: Pick card based on suit/rank. Just get 1 image working now
bi3.UriSource = new Uri("diamond-1.png", UriKind.Relative);
bi3.EndInit();
img.Stretch = Stretch.Fill;
img.Source = bi3;
results.Add(img);
}
return results;
}
}
Run Code Online (Sandbox Code Playgroud)
在我使用的XAML代码中:
<Window.Resources>
<DataTemplate x:Key="ImageCell">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding PlayerCardImages}" Width="200" Height="200" Stretch="Fill" ToolTip="Add tooltip"/>
</StackPanel> …Run Code Online (Sandbox Code Playgroud) 所以我一个绑定List的ListView,其中List有一个类型的项目Album,它有很多特性,包括.Cover,我是在磁盘上的图像.好吧,因为我不知道需要什么类型的图像以及如何加载它们(我只知道使用Winforms的图像类型),我还不知道它的类型.
有人可以展示或发布一个快速样本,其中显示这类项目使用其.Cover属性显示为某个固定大小的图像?
实质上,这将显示:
.Cover应该是什么类型