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:

XML
<Window x:Class="WpfCanvasTest.Test"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="LearnWPF - XmlDataBinding" Height="300" Width="300"
    x:Name="Window"
    >
    <Window.Resources>
      <XmlDataProvider x:Key="EmployeeData" XPath="root/advertiser">
        <x:XData>
           <!--xml data island-->
          <root>
            <advertiser>
              <name>Pfizer Ltd</name>
              <address>Ramsgate Road, Sandwich</address>
              <postcode>CT13 9NJ</postcode>
              <adv_email />
              <fax />
              <tel>01304 616161</tel>
            </advertiser>
            <vacancy>
              <title>Product Manager</title>
              <refrence>62209</refrence>
              <contact />
              <location>UK</location>
              <type>Permanent</type>
              <advjobref>942042</advjobref>
              <email />
              <joburl></joburl>
              <jobdesc />
              <region>UK - All</region>
              <sector1>Medical Sales</sector1>
              <sector2 />
              <sector3 />
              <tel>01304 616161</tel>
            </vacancy>
          </root>
        </x:XData>
      </XmlDataProvider>
      <XmlDataProvider x:Key="LearnWPFFeed"
                       Source="http://learnwpf.com/Rss.ashx"
                       XPath="//item" />
    </Window.Resources>
    <StackPanel>
      <!-- binding to data island -->
      <StackPanel DataContext="{StaticResource EmployeeData}">
        <TextBlock Text="{Binding XPath=name}" FontSize="30" />
      </StackPanel>
    </StackPanel>
  </Window>



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
Posted
Updated 2-Nov-10 22:35pm
v3
Comments
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,
Martin
 
Share this answer
 
Comments
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