构造数据:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace WpfApplication2{ ////// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : Window { Random rnd = new Random(); public MainWindow() { InitializeComponent(); var tlist = new List(); for (int i = 0; i < 10; i++) { tlist.Add(new Person() { Name = "张三" + i, Age = rnd.Next(20) }); } list= tlist.Select(x => new { x, id = Guid.NewGuid() }).OrderBy(y => y.id).Select(z => z.x).ToList (); this.DataContext = this; } public List list { get; set; } } public class Person { public string Name { get; set; } public int Age { get; set; } }}
界面显示: