XML Databinding problem in XAML

Posted on 2009-04-30
Last Modified: 2013-11-12
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.


<Window x:Class="Main"




    Title="Twittered" Height="300" Width="550" Name="Main" AllowsTransparency="False" WindowStyle="ThreeDBorderWindow">


        <ObjectDataProvider x:Key="TimelineDataSource"  ObjectType="{x:Type src:Timeline}"/>

        <XmlDataProvider x:Key="XMLTimeline" Source="/bin/debug/timeline.xml" />






            MinHeight="240" MaxWidth="342"

              ItemsSource="{Binding XPath=/status, Mode=OneWay, Source={StaticResource XMLTimeline}}">












                        <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding XPath=text}"/>





        <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>




<?xml version="1.0" encoding="UTF-8"?>

<statuses type="array">


  <created_at>Thu Apr 30 04:01:56 +0000 2009</created_at>


  <text>Watching lost</text>

  <source>&lt;a href=&quot;;&gt;TinyTwitter&lt;/a&gt;</source>








    <name>Cory Takahashi</name>


    <location>Los Angeles, CA</location>












    <created_at>Fri Feb 06 16:47:22 +0000 2009</created_at>



    <time_zone>Pacific Time (US &amp; Canada)</time_zone>









  <created_at>Thu Apr 30 03:08:26 +0000 2009</created_at>


  <text>got to dennison, ohio little while ago. exhausted. never in my wildest dreams thought Ohio was this hilly.</text>









    <name>Phil Keoghan</name>














    <created_at>Wed Mar 04 20:53:45 +0000 2009</created_at>












Open in new window

Question by:ReinisB
    LVL 8

    Accepted Solution

    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 "

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

    Open in new window

    LVL 2

    Author Closing Comment

    I knew it was something staring me in the face.  Thanks Dave.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now