【发布时间】:2014-09-04 09:07:24
【问题描述】:
public DataTable Data
{
get { return _tableData; }
set
{
if (Equals(value, _tableData)) return;
_tableData = value;
NotifyOfPropertyChange();
}
}
我有我的 xaml 数据网格:
<DataGrid
HorizontalAlignment="Stretch"
IsReadOnly="True" ItemsSource="{Binding Data}"
AutoGenerateColumns="True">
</DataGrid>
可以说,有一个DataTable 将在下一列:
- B 栏
- 一栏
- D 柱
- C 柱
我需要一种通过xaml 按字母顺序表示它们的方法:
- 一栏
- B 栏
- C 柱
- D 柱
我已经尝试过的:
- 具有可排序属性的集合视图源:
<CollectionViewSource x:Key="ColumnsDatagridViewSource" Source="{Binding Data}"> <CollectionViewSource.SortDescriptions> <componentModel:SortDescription PropertyName="ColumnHeader"/> </CollectionViewSource.SortDescriptions> </CollectionViewSource>
没有帮助,出现了一个数组。它试图在列标题字符串中找到这个属性。
- IValue 转换器,它帮助我进行树视图排序:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { System.Collections.IList collection = value as System.Collections.IList; ListCollectionView view = new ListCollectionView(collection); SortDescription sort = new SortDescription(parameter.ToString(), ListSortDirection.Ascending); view.SortDescriptions.Add(sort); return view; }
【问题讨论】: