开发者

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开发者_如何学Python 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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜