C# 从下到上排序项控件

C# 从下到上排序项控件,c#,wpf,xaml,C#,Wpf,Xaml,我需要把这张桌子从下到上列出来。0应位于底部。 做了很多谷歌搜索,但我发现的大多数建议是使用ListBox或覆盖UniformGrid(顺便说一句,我也尝试过)。这些建议中没有一个对我有效 <Window x:Class="Double_ItemsControl.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schem

我需要把这张桌子从下到上列出来。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>

使用系统;
使用System.Collections.Generic;
使用System.Collections.ObjectModel;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间双\u项控件
{
公共类视图模型
{
公共ObservableCollection内部列表{get;set;}
公共可观测集合外部列表{get;set;}
公共视图模型()
{
InnerList=新的ObservableCollection(){0,1,2,3,4};
OuterList=新的ObservableCollection();
对于(int i=1;i<35;i++)
{
如果(i%5==0)
{
添加(内部列表);
}
} 
}
}
}
有什么建议吗


顺便说一句:我需要使用两个ItemControls。

您以前是否尝试过按相反的顺序对ObservableCollection进行排序?您可以在XAML中定义
CollectionViewSource
,并可以
SortDescription
使用
方向
进行描述。您好@user1672994谢谢您的建议。我试试看,你也许可以返回一个排序的iEnumerable并绑定到它。但不确定在添加或从ObservableCollection中删除时它是否会更新。
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);
                 }
            } 
        }
    }
}