绑定的资源 然后去排序
void GridViewColumnHeader_Click(object sender, RoutedEventArgs e)
{
var r = e.Source as GridViewColumnHeader;
}
想从GridViewColumnHeader的Click事件 找到这个Header所属的GridView(ListView)
怎样做?
是想找到他绑定的资源 然后去排序
void GridViewColumnHeader_Click(object sender, RoutedEventArgs e)
{
var columnName = (e.OriginalSource as GridViewColumnHeader).Content as string;
var view = CollectionViewSource.GetDefaultView((e.Source as ListView).ItemsSource);
view.SortDescriptions.Clear();
view.SortDescriptions.Add(new SortDescription(columnName, ListSortDirection.Ascending));
}
然后在ListView上写
GridViewColumnHeader.Click="GridViewColumnHeader_Click"
可以通用