The
XmlDataProvider
class is not a
DependencyObject
, so you cannot bind its
Document
property to a view-model property.
Instead, you would read the XML file from your view-model, convert it to a list of C# objects, and bind your data to that list.
public class Language
{
public Lanuage(XElement element)
{
Id = (int)element.Attribute("id");
Name = (string)element.Element("name");
CultureCode = (string)element.Element("culture");
}
public int Id { get; }
public string Name { get; }
public string CultureCode { get; }
}
public class YourViewModel : ViewModelBase
{
public IReadOnlyList<Language> Languages { get; } = LoadLanguages();
private static IReadOnlyList<Language> LoadLanguages()
{
XDocument doc = XDocument.Load("Languages.xml");
return doc.Root.Elements("language").Select(el => new Language(el)).ToList();
}
}
<Window.DataContext>
<local:YourViewModel/>
</Window.DataContext>
<Grid>
<ComboBox x:Name="cmbName" ItemsSource="{Binding Path=Languages}" DisplayMemberPath="Name" />
</Grid>