我想更改listview中的选定项目,因此我更改了listView.SelectedItem,但现在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);
}
}