XML Databinding problem in XAML

What is wrong with the databinding of the XAML file to the XML file?

The XML file is in the /bin/debug folder of the project.  The listbox is supposed to list the <text> element content for each <status> element.  The formatting is not completed .. it's mainly a placeholder until i get the content working - sorry i know it's not the best code! When I build the project, nothing is shown in the listbox.  It doesn't seem to be reading from the XML file correctly.

Originally the listbox was databound to an observableCollection object and it was working but the XMLDataProvider is a more sensible way to go so I'm trying to redo it.

The XAML file is listed first in the code section, followed by an abbreviated version of the XML file.

The file is only currently in the /bin/debug folder because I am trying to get it to work.  If anyone has a suggestion where it would be more appropriate to put the file, it would be appreciated.  The XML file must be overwritten regularly, and it should be user-scoped if possible.

Thanks,

Reinis
<Window x:Class="Main"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:Twittered"
    Title="Twittered" Height="300" Width="550" Name="Main" AllowsTransparency="False" WindowStyle="ThreeDBorderWindow">
    <Window.Resources>
        <ObjectDataProvider x:Key="TimelineDataSource"  ObjectType="{x:Type src:Timeline}"/>
        <XmlDataProvider x:Key="XMLTimeline" Source="/bin/debug/timeline.xml" />
    </Window.Resources>
    <Grid>
        <ListBox 
            Margin="12,12,174,12" 
            Name="lstboxTimeline" 
            MinHeight="240" MaxWidth="342"
              ItemsSource="{Binding XPath=/status, Mode=OneWay, Source={StaticResource XMLTimeline}}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding XPath=text}"/>
                    </Grid>
 
                </DataTemplate>
            </ListBox.ItemTemplate>
 
        </ListBox>
        <TextBox Margin="0,79,12,70" Name="txtboxUpdate" HorizontalAlignment="Right" Width="156" MaxLength="140" TextWrapping="Wrap" />
        <Button Height="23" HorizontalAlignment="Right" Margin="0,0,12,12" Name="btnLogOut" VerticalAlignment="Bottom" Width="75">Log In</Button>
        <Button Height="23" HorizontalAlignment="Right" Margin="0,0,93,12" Name="btnLogIn" VerticalAlignment="Bottom" Width="75">Log On</Button>
        <Button Height="23" HorizontalAlignment="Right" Margin="0,0,12,41" Name="btnUpdate" VerticalAlignment="Bottom" Width="75">Tweet!</Button>
        <Button Height="23" HorizontalAlignment="Right" Margin="0,0,93,41" Name="btnClear" VerticalAlignment="Bottom" Width="75">Clear</Button>
        <MediaElement HorizontalAlignment="Right" Margin="0,12,12,0" Name="UserImage" Width="84" Height="61" VerticalAlignment="Top" />
        <Button Height="61" HorizontalAlignment="Right" Margin="0,12,102,0" Name="btnRefresh" VerticalAlignment="Top" Width="66">Refresh</Button>
    </Grid>
 
</Window>
 
_________________________________________________________
 
<?xml version="1.0" encoding="UTF-8"?>
<statuses type="array">
<status>
  <created_at>Thu Apr 30 04:01:56 +0000 2009</created_at>
  <id>1656132636</id>
  <text>Watching lost</text>
  <source>&lt;a href=&quot;http://www.tinytwitter.com/&quot;&gt;TinyTwitter&lt;/a&gt;</source>
  <truncated>false</truncated>
  <in_reply_to_status_id></in_reply_to_status_id>
  <in_reply_to_user_id></in_reply_to_user_id>
  <favorited>false</favorited>
  <in_reply_to_screen_name></in_reply_to_screen_name>
  <user>
    <id>20250549</id>
    <name>Cory Takahashi</name>
    <screen_name>ctak</screen_name>
    <location>Los Angeles, CA</location>
    <description></description>
    <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/151165091/IMG_1440_normal.JPG</profile_image_url>
    <url></url>
    <protected>true</protected>
    <followers_count>3</followers_count>
    <profile_background_color>BADFCD</profile_background_color>
    <profile_text_color>0C3E53</profile_text_color>
    <profile_link_color>FF0000</profile_link_color>
    <profile_sidebar_fill_color>FFF7CC</profile_sidebar_fill_color>
    <profile_sidebar_border_color>F2E195</profile_sidebar_border_color>
    <friends_count>35</friends_count>
    <created_at>Fri Feb 06 16:47:22 +0000 2009</created_at>
    <favourites_count>1</favourites_count>
    <utc_offset>-28800</utc_offset>
    <time_zone>Pacific Time (US &amp; Canada)</time_zone>
    <profile_background_image_url>http://static.twitter.com/images/themes/theme12/bg.gif</profile_background_image_url>
    <profile_background_tile>false</profile_background_tile>
    <statuses_count>298</statuses_count>
    <notifications>false</notifications>
    <following>false</following>
  </user>
</status>
<status>
  <created_at>Thu Apr 30 03:08:26 +0000 2009</created_at>
  <id>1655726982</id>
  <text>got to dennison, ohio little while ago. exhausted. never in my wildest dreams thought Ohio was this hilly.</text>
  <source>web</source>
  <truncated>false</truncated>
  <in_reply_to_status_id></in_reply_to_status_id>
  <in_reply_to_user_id></in_reply_to_user_id>
  <favorited>false</favorited>
  <in_reply_to_screen_name></in_reply_to_screen_name>
  <user>
    <id>22832401</id>
    <name>Phil Keoghan</name>
    <screen_name>PhilKeoghan</screen_name>
    <location></location>
    <description></description>
    <profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/98139625/97613_D0284b_normal.jpg</profile_image_url>
    <url></url>
    <protected>false</protected>
    <followers_count>4113</followers_count>
    <profile_background_color>9ae4e8</profile_background_color>
    <profile_text_color>000000</profile_text_color>
    <profile_link_color>0000ff</profile_link_color>
    <profile_sidebar_fill_color>e0ff92</profile_sidebar_fill_color>
    <profile_sidebar_border_color>87bc44</profile_sidebar_border_color>
    <friends_count>18</friends_count>
    <created_at>Wed Mar 04 20:53:45 +0000 2009</created_at>
    <favourites_count>0</favourites_count>
    <utc_offset></utc_offset>
    <time_zone></time_zone>
    <profile_background_image_url>http://static.twitter.com/images/themes/theme1/bg.gif</profile_background_image_url>
    <profile_background_tile>false</profile_background_tile>
    <statuses_count>158</statuses_count>
    <notifications>false</notifications>
    <following>0</following>
  </user>
</status>
</statuses>

Open in new window

LVL 2
ReinisBAsked:
Who is Participating?
 
unmeshdaveConnect With a Mentor Commented:
check the attached lines.
1. you need to define root in your XMLDataProvider.
2. you need to put correct syntex for XPath in ListBox. Either you have to put "status" or "./status". because "/status" will search "status" element as root element.
3. If you do not define root in XMLDataProvider, you need to define XPath as "
/statuses/status"

<XmlDataProvider x:Key="XMLTimeline" Source="timeline.xml" XPath="/statuses" />
 
===========
<ListBox 
            Margin="12,12,174,12" 
            Name="lstboxTimeline" 
            MinHeight="240" MaxWidth="342"
              ItemsSource="{Binding XPath=./status, Source={StaticResource XMLTimeline}}">

Open in new window

0
 
ReinisBAuthor Commented:
I knew it was something staring me in the face.  Thanks Dave.
0
All Courses

From novice to tech pro — start learning today.