C# Databinding an XML to a listview WPF C# Databinding an XML to a listview WPF wpf wpf

C# Databinding an XML to a listview WPF


No extra cs code is needed.

Source property of XmlDataProvider is a Uri, not a file path. So if you write there only “kunden.xml”, your application is looking for this file in application resources. To add this file to application resources you shall add your xml file to your project (Add->Existing item). In files its properties set "Build Action" to "Resource"

If you want your app to load from standalone file (i.e. kunden.xml shall be in the same folder where your exe is), you shall:

  • Copy xml to output folder: manually or automatically, i.e. set kunden.xml "Build Action" to "None", but "Copy To Output Directory" to "Copy if newer"
  • Change Source=”kunden.xml” to Source="pack://siteoforigin:,,,/kunden.xml"

If you want to use absolute name of the file, simply use Source=“file:///D:/my/absolute/path/kunden.xml”.