0

在我的 windows phone 项目中,我有一个来自 xml 的列表框绑定数据

<ListBox x:Name="listBox02">
    <ListBox.ItemTemplate>
         <DataTemplate>
              <StackPanel Margin="20" >
                  <TextBlock Text="{Binding Namee}"/>
                   <TextBlock Text="{Binding Examinoo}"/>
                   <TextBlock Text="{Binding Statuss}"/>
                    <!--<TextBlock Text="{Binding Idd}"/>-->
              </StackPanel>
         </DataTemplate>
    </ListBox.ItemTemplate>
 </ListBox>

使用

XDocument loadedCustomData = XDocument.Load("PeopleCustom.xml");
var filteredData = 
    from c in loadedCustomData.Descendants("Mathima")
    where c.Attribute("Id").Value == "1"
    select new Iatriki() {
                  Namee = "Ονομα: " + c.Attribute("Name").Value,
                  Examinoo = "Εξάμηνο: " + c.Attribute("Examino").Value,
                  Idd = c.Attribute("Id").Value,
                  Statuss = c.Attribute("Status").Value,
           };

 listBox02.ItemsSource = filteredData;

单击按钮时,我想按“Examinoo”对列表进行排序

这是按钮的事件处理程序:

private void btn_sort_Click(object sender, RoutedEventArgs e)
{
    listBox02.Items.SortDescriptions.Add(
                new SortDescription("Content", ListSortDirection.Descending));

}

我收到以下错误:

System.Windows.Controls.ItemCollection'不包含'SortDescriptions'的定义,并且找不到接受'System.Windows.Controls.ItemCollection'类型的第一个参数的扩展方法'SortDescriptions'(您是否缺少 using 指令或程序集参考?)`

4

1 回答 1

2

对于同样的问题,我正在遵循这种方法

在 XDocument 行之后,删除您的列表框行

listBox02.ItemsSource = filteredData; //remove this line and add the following 2 lines

ObservableCollection<Iatriki> myCollection = new ObservableCollection<Iatriki>(filteredData);
listBox02.ItemsSource = myCollection;

然后在按钮中单击

listBox02.ItemsSource = myCollection.OrderBy(item => item.Examinoo);
于 2012-08-29T11:46:53.780 回答