C# 如何在xaml c中显示选择项#

C# 如何在xaml c中显示选择项#,c#,xaml,listview,selecteditem,C#,Xaml,Listview,Selecteditem,在我更改listview.SelectedItem之前,我想更改我的listview中的选定项,但现在选择内容不会显示在xaml窗口中,而是设置了SelectedItem的值。 如何在xaml窗口上显示所选内容 “schueler”是我的列表视图 //save the value of the old datasource XmlElement selectet = (XmlElement)schueler.SelectedItem; string name =

在我更改listview.SelectedItem之前,我想更改我的listview中的选定项,但现在选择内容不会显示在xaml窗口中,而是设置了SelectedItem的值。 如何在xaml窗口上显示所选内容

“schueler”是我的列表视图

//save the value of the old datasource
        XmlElement selectet = (XmlElement)schueler.SelectedItem;
        string name = selectet.GetAttribute("MachineId");

        //Refreshing the datasource
        XmlDataProvider oProv = schueler.DataContext as XmlDataProvider;
        oProv.Refresh();

        //Select old 
        for (int i = 0; i < schueler.Items.Count; i++ )
        {
            XmlElement item = (XmlElement)schueler.Items.GetItemAt(i);
            Console.WriteLine(item.GetAttribute("MachineId"));
            if(item.GetAttribute("MachineId")==name)
            {
                schueler.SelectedItem = schueler.Items.GetItemAt(i);
            }
        }
//保存旧数据源的值
xmlement selectet=(xmlement)schueler.SelectedItem;
字符串名称=selectet.GetAttribute(“MachineId”);
//刷新数据源
XmlDataProvider oProv=schueler.DataContext作为XmlDataProvider;
oProv.Refresh();
//选择旧的
对于(int i=0;i
当您向我们展示您的尝试时,这将非常有帮助。等等,您想实现什么?我不明白。我有一个xml,可以从中获取列表视图的数据,现在我想更新源代码,因为在xml文件中进行了更改。在重新加载数据源之后,我希望选择数据源中的旧值,这样用户就不必在刷新数据源后再次选择它datasource@Mirra请看答案,编辑的版本应该适合您。当您向我们展示您所尝试的内容时,它将非常有用。等等,您希望实现什么?我不明白。我有一个xml,可以从中获取列表视图的数据,现在我想更新源代码,因为在xml文件中进行了更改。在重新加载数据源之后,我希望选择数据源中的旧值,这样用户就不必在刷新数据源后再次选择它datasource@Mirra请参见答案,编辑的版本应该适合您。