Blog

View Blog

Oct 1

Written by: Rainer Stropek
10/1/2007

During the last weeks I have not written any blog entries. Why? Together with Karin I have been working on our new book "WPF and XAML" that will come out in December (check out the book at Amazon). I never thought that writing 550 pages could be so hard. However, we finished the alpha-version of our manuscript yesterday. Therefore I have time to write some blogs again. Today about XmlDataProvider.

If you want to access XML data in data binding expressions, MSDN tells you that you have to use the XmlDataProvider-class. This class is - just like ObjectDataProvider - a DataSourceProvider:

XmlDataProvider...

  • ...can access XML data that is embedded into a XAML file
  • ...can load XML data using a URI (e.g. reading an existing XML file from disk)
  • ...offers a Document property which you can assign your own instance of XmlDocument. You can generate or load the XmlDocument in any way you want.
  • ...can load inline XML data or XML data from a file in a separate worker thread (UI is not blocked while loading the XML data)

Here is a short sample that shows how to use XmlDataProvider. It uses inline XML data that is embedded into the XAML file. The sample also shows how to create a binding expression that references the XmlDataProvider-object.

What's happening inside? XmlDataProvider loads (asynchronously or synchronously, depending on the setting in the IsAsynchronous property) the XML data into a XmlDocument-object. That leads us to the question that Karin and I was asking ourselves: Why using XmlDataProvider if we build the XmlDocument-object in code? Do we have to use XmlDataProvider and assign our own XmlDocument instance to the Document-property?

The answer is no! In such cases you can directly embed the XmlDocument object and forget about XmlDataProvider. The important thing is that you do not loose the ability to create data binding expressions using XPath=... Check out the following code sample. It works fine! Here is the XAML code:

Here is the code behind file in C#:

Tags:

4 comments so far...

Re: Back again - and writing about XamlDataProvider

I am so happy you're back again, 'cause I was missing your blog entries. I always follow your advice and everything becomes clear to me, as, for example, in this case. I faced some problems trying to use XmlDataProvider, now I can do it easily. By the way, I am very obliged to you for your book "WPF and XAML", which I had an opportunity to download on search engine on torrent files http://www.picktorrent.com . It is really worth reading. My congratulations!

By Dereck on   12/25/2009

Re: Back again - and writing about XamlDataProvider

this page has just saved my sscp arse. i was having the exact same problem using sql server 2005 64 bit updating a table in oracle 8i and kept getting random bookmark errors. testing this code was a maddening process, because it tcp certification would work about 1/2 the time. recoding the proc using the EXEC(sql, params) at linked server is not only stable but fast and saved this project from having to revert the database to sql server vmware test prep 2000.

By daineldavid on   2/1/2010

Re: Back again - and writing about XamlDataProvider

,I am using MSSQL 2k, and I have a linked server set up to an Oracle RDBversion 7. It goes thru an OLE DB provider for ODBC drivers on a systemDSN, which is using an Oracle RDB ODBC driver version 3.0.2.The problem occurs when I send a query that returns zero rows - queryanalyzer just does not complete nor return. This problem is not seenwhen there are rows being returned.
Please give suggestion to remove this.

By 17 und 4 Casino on   2/13/2010

Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment    Cancel  

Newsletter

Sie möchten im Newsletter über aktuelle technische Entwicklungen und Neuigkeiten rund um cubido informiert werden?

Newsletter abonnieren ...

Blog