Click here to Skip to main content
15,876,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my xaml:

<Window x:Class="WpfCanvasTest.Test"
    Title="LearnWPF - XmlDataBinding" Height="300" Width="300"
      <XmlDataProvider x:Key="EmployeeData" XPath="root/advertiser">
           <!--xml data island-->
              <name>Pfizer Ltd</name>
              <address>Ramsgate Road, Sandwich</address>
              <postcode>CT13 9NJ</postcode>
              <adv_email />
              <fax />
              <tel>01304 616161</tel>
              <title>Product Manager</title>
              <contact />
              <email />
              <jobdesc />
              <region>UK - All</region>
              <sector1>Medical Sales</sector1>
              <sector2 />
              <sector3 />
              <tel>01304 616161</tel>
      <XmlDataProvider x:Key="LearnWPFFeed"
                       XPath="//item" />
      <!-- binding to data island -->
      <StackPanel DataContext="{StaticResource EmployeeData}">
        <TextBlock Text="{Binding XPath=name}" FontSize="30" />

But it's not displaying anything :(
The name is displayed if I remove the vacancy element and its child elements.

Don't know what is wrong
PS: This is my first time I am trying to binding textblock to xml
Updated 2-Nov-10 22:35pm
Kunal Chowdhury «IN» 15-Aug-10 11:19am    
Reason for Edit: Properly format the code
Dalek Dave 3-Nov-10 4:35am    
Edited for Grammar.

1 solution

Hi There,

To make this work I needed to provide an empty namespace on the root element:
<root xmlns="">

This is a requirement for applying XPath queries to a data island that is inline within the XAML.

I hope this helps to get you going,
Share this answer
Dalek Dave 3-Nov-10 4:35am    
Good Call.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900