I have a Listview which is bound to a XML file. The values of the different nodes of the XML files can be changed using Textboxes. If I change the value of an element which is directly bound to the element in the listview everything works fine. The problem starts if I change values in the XML file depending on other values and then I have to refresh the XML dataprovider to see the changes in the listbox. If I do so, then my previously SelectedItem is lost. I also tried to save the SelectedItem and reload it after refreshing, but it didn't work.
Is there an alternative method to refresh a XML dataprovider? Or is there a better way to refreh the ListView?
in Window1.xaml:
...
<Grid.DataContext>
<XmlDataProvider x:Name="VoltageData" Source="Voltages.xml" XPath="Voltages/Voltage" />
</Grid.DataContext>
...
in Window1.xaml.cs:
...
xmlDoc.Save(VoltageData.Source.LocalPath);
VoltageData.Refresh();
...
SelectedValue
) of the List View.SelectedValue
) to the ListView.This way it will maintain the selection. If the selected Item (or Value) is bound using WPF binding then update the object \ property representing the source path of the binding.