简体   繁体   中英

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM