views:

26

answers:

1

in my browser wpf application i use databinding to xml that comes from my database. to bind it the better way i use the XmlDataProvider.

in the beginning i declare

<Grid.DataContext>
    <XmlDataProvider x:Name="listdataxml" XPath="EssenceList/Essence" Source="model.xml"/>
</Grid.DataContext>

but later i need to point it to a new XDocument. The question: is there a way to set my XmlDataProvider to an XDocument, without saving it somewhere and using URI?

+1  A: 

You can convert the XDocument to an XmlDocument in memory and then set the Document property on listdataxml. See this StackOverflow question for how to convert from an XDocument to an XmlDocument.

Put together, it will look like this:

var xmlDocument = new XmlDocument();
using (var xmlReader = xDocument.CreateReader())
{
    xmlDocument.Load(xmlReader);
}
listdataxml.Document = xmlDocument;
Quartermeister
thanks, that works))