如何编辑 ListView 中的项目?

How to edit an Item in a ListView?

在我的代码隐藏中,如何编辑 ListView 中的值?
我有这个:

<ListView x:Name="EntreesListView">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="Entrees" 
                      Width="Auto" 
                      DisplayMemberBinding="{Binding Name}"/>

还有这个:

// Select all data in my database and add them into my column
private void ListViewAllEntrees()
{
   using (var selectAllEntrees = new Database1Entities())
   {
       var selectName =
           from monEntreeList
           in selectAllEntrees.Entrees
           select monEntreeList;
           foreach (var entree in selectName)
           {
              EntreesListView.Items.Add(new {entree.Name});
           }
// Now I want to edit for example the value at index 5
// I click on a button which is in my ListView too
var item = (sender as FrameworkElement).DataContext;
int indexEntrees = EntreesListView.Items.IndexOf(item);
// Now I have my index
// I can RemoveAt(indexEntrees) and make a new Add but it is not a solution

请问我该如何编辑索引 5 处的值名称?

有几种方法可以完成此任务。

而不是添加列表中的每个项目。您可以使用

EntreesListView.ItemSource = selectName;
EntreesListView.Refresh();

现在你的答案,如何获取或修改第 5 个或任何元素 在某些事件中,当您获得被单击元素的索引时

//get the item from original list
var obj = selectName[index];
//make changes to your object and again change the ItemSource
EntreesListView.ItemSource = selectName;
EntreesListView.Refresh();