我需要从下到上列出此表。 0应该在底部。 做了很多谷歌搜索,但我发现最多的建议是使用ListBox或覆盖UniformGrid(我也尝试过)。没有这些建议对我有用。
<Window x:Class="Double_ItemsControl.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Double_ItemsControl"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
<Grid>
<ItemsControl ItemsSource="{Binding Path=OuterList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="6" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Double_ItemsControl
{
public class ViewModel
{
public ObservableCollection<int> InnerList { get; set; }
public ObservableCollection<ObservableCollection<int>> OuterList { get; set; }
public ViewModel()
{
InnerList = new ObservableCollection<int>() { 0,1,2,3,4 };
OuterList = new ObservableCollection<ObservableCollection<int>>();
for (int i = 1; i < 35; i++)
{
if (i % 5 == 0)
{
OuterList.Add(InnerList);
}
}
}
}
}
有什么建议吗?
BTW:我需要使用两个ItemControl。