Binding XML Data to WPF

J

jpuopolo

Hi all,

This is a cross-cutting question...

In our app, we use LINQ-to-SQL to read some data from SQL Server. One
of the columns we read from SQL Server is an XML column. When we
execute the LINQ query, we get a well-formed object. This well-formed
object contains several fields, one of which is an XElement. This
XElement corresponds to the SQL Server's XML column - so far, so good.

The problem we have is trying to then bind the returned object to a
WPF-based form using data binding. If we try the following:

<TextBox Text={Binding Path=SimpleXml ........}

We get a string representation of the XML block; however, if we try
this:

<TextBox Text={Binding XPath=SimpleXml/employee......} we get the
following error:

System.Windows.Data Error: 43 : BindingExpression with XPath cannot
bind to non-XML object.

We've tried a bunch of different XPath-style expressions in order to
pull out what we need - and we keep getting this error. Nothing seems
to work.

Thoughts?

Thanks,
jpuopolo
 
A

Andy O'Neill

jpuopolo said:
Hi all,

This is a cross-cutting question...

In our app, we use LINQ-to-SQL to read some data from SQL Server. One
of the columns we read from SQL Server is an XML column. When we
execute the LINQ query, we get a well-formed object. This well-formed
object contains several fields, one of which is an XElement. This
XElement corresponds to the SQL Server's XML column - so far, so good.

The problem we have is trying to then bind the returned object to a
WPF-based form using data binding. If we try the following:

<TextBox Text={Binding Path=SimpleXml ........}

We get a string representation of the XML block; however, if we try
this:

<TextBox Text={Binding XPath=SimpleXml/employee......} we get the
following error:

System.Windows.Data Error: 43 : BindingExpression with XPath cannot
bind to non-XML object.

We've tried a bunch of different XPath-style expressions in order to
pull out what we need - and we keep getting this error. Nothing seems
to work.

Thoughts?

Thanks,
jpuopolo
I never tried to bind to xml that's within a type, not sure that's going to
work.
I would be inclined to convert the xml to a type/collection.
If it's variable then I would use an observable dictionary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top