WPF MVVM ListView动态绑定数据
2021-01-29 22:13
标签:wrap height span -keep mode none containe inline listview ? 界面 ? .cs 新建一个 Person类 MainWindowViewModel 效果 ? WPF MVVM ListView动态绑定数据 标签:wrap height span -keep mode none containe inline listview 原文地址:https://www.cnblogs.com/CityOfThousandFires/p/11682088.htmlWindow x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
Grid>
ListView ItemsSource="{Binding Path=PersonCollectionView}">
ListView.View>
GridView>
GridViewColumn DisplayMemberBinding="{Binding Path=Name}">
GridViewColumnHeader Command="{Binding Path=SortCommand}"
CommandParameter="Name">姓名GridViewColumnHeader>
GridViewColumn>
GridViewColumn DisplayMemberBinding="{Binding Path=Age}">
GridViewColumnHeader Command="{Binding Path=SortCommand}"
CommandParameter="Age">年龄GridViewColumnHeader>
GridViewColumn>
GridView>
ListView.View>
ListView>
Grid>
Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainWindowViewModel();
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
public class MainWindowViewModel
{
public MainWindowViewModel()
{
personCollection.Add(new Person() { Name = "刘二", Age = 17 });
personCollection.Add(new Person() { Name = "张三", Age = 18 });
personCollection.Add(new Person() { Name = "李四", Age = 17 });
personCollection.Add(new Person() { Name = "王五", Age = 19 });
personCollection.Add(new Person() { Name = "周六", Age = 18 });
personCollection.Add(new Person() { Name = "胡二", Age = 16 });
personCollection.Add(new Person() { Name = "黄七", Age = 14 });
personCollection.Add(new Person() { Name = "朱八", Age = 15 });
personCollection.Add(new Person() { Name = "周四", Age = 13 });
this.SortCommand = new DelegateCommandstring>(this.Sort);
}
private ObservableCollection
文章标题:WPF MVVM ListView动态绑定数据
文章链接:http://soscw.com/index.php/essay/48866.html