大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
<!--xaml-->
<ListView Margin="51,54,70,64" x:Name="lvList" GridViewColumnHeader.Click="lvList_Click_1" ItemsSource="{Binding}" >
<ListView.View>
<GridView >
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="50"></GridViewColumn>
<GridViewColumn Header="Age" DisplayMemberBinding="{Binding Age}" Width="50"></GridViewColumn>
<GridViewColumn Header="Email" DisplayMemberBinding="{Binding Email}" Width="50"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
//后台代码
private void lvList_Click_1(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is GridViewColumnHeader)
{
//获得点击的列
GridViewColumn clickedColumn = (e.OriginalSource as GridViewColumnHeader).Column;
if (clickedColumn != null)
{
//Get binding property of clicked column
string bindingProperty = (clickedColumn.DisplayMemberBinding as Binding).Path.Path;
//获得listview项是如何排序的
SortDescriptionCollection sdc = this.lvList.Items.SortDescriptions;
//按升序进行排序
ListSortDirection sortDirection = ListSortDirection.Ascending;
if (sdc.Count > 0)
{
SortDescription sd = sdc[0];
sortDirection = (ListSortDirection)((((int)sd.Direction) + 1) % 2);
sdc.Clear();
}
sdc.Add(new SortDescription(bindingProperty, sortDirection));
}
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/186280.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...