Sta*_*mpy 1 .net c# sorting wpf observablecollection
我ObservableCollection<KeyValuePair<int, String>>()在文本框上绑定了一个名为TestList的文件,我希望按照它排序int.我尝试了以下但它没有对集合进行排序:
new ObservableCollection<KeyValuePair<int, string>>(
TestList .Where(p => p.Key > 0)
.GroupBy(p => p.Key)
.Select(grp => grp.First())
.OrderBy(p => p.Key)
);
Run Code Online (Sandbox Code Playgroud)
我该如何对系列进行排序?Binding还能运作吗?
编辑(也不起作用):
public ObservableCollection<KeyValuePair<int, String>> TestList
{
get { return testList; }
set {
testList = value;
NotifyPropertyChanged("TestList");
}
}
public void Test(int index)
{
TestList.RemoveAt(index);
TestList = new ObservableCollection<KeyValuePair<int, string>>(TestList.OrderBy(p => p.Key));
}
Run Code Online (Sandbox Code Playgroud)
和GUI:
<TextBox Grid.Column="0" IsReadOnly="True"
Text="{Binding Path=Value , Mode=OneWay}" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
996 次 |
| 最近记录: |