user362249
user362249

Reputation: 65

set XmlDataProvider source without saving file

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?

Upvotes: 1

Views: 1132

Answers (1)

Quartermeister
Quartermeister

Reputation: 59129

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;

Upvotes: 3

Related Questions