Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 267409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:32:48+00:00 2026-05-11T23:32:48+00:00

I’m trying to do some WPF databinding, but I’m a little hung up at

  • 0

I’m trying to do some WPF databinding, but I’m a little hung up at the moment. I have two listboxes and an XML file. The first listbox successfully binds to the XML source. However, when I try to bind to a child of the selected item from first listbox as the source for the second list box, nothing appears. The goal being something like an index or look-up (selecting one index results in finding the related items). Am I missing something here for the databinding? XAML and XML below.

XAML:

<Window x:Class="MyTool.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="600" Width="800">
    <Window.Resources>
        <XmlDataProvider x:Key="AllDeployments" XPath="Deployments" Source="Deployments.xml" />
        <DataTemplate x:Key="dtDeployments">
            <StackPanel FlowDirection="LeftToRight" Orientation="Horizontal">
                <TextBlock Text="{Binding XPath=@Name}" />
                <TextBlock Text=" - "/>
                <TextBlock Text="{Binding XPath=@Date}" />
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="dtFiles">
            <TextBlock Text="{Binding XPath=File}" />
        </DataTemplate>
    </Window.Resources>
    <Grid Name="gMain">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="2"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Menu Grid.Column="0" Grid.ColumnSpan="3"></Menu>
        <ListBox Grid.Column="0" Name="lbDeployment" 
                 ItemsSource="{Binding Source={StaticResource AllDeployments}, XPath=Deployment}"
                 ItemTemplate="{StaticResource dtDeployments}"></ListBox>
        <GridSplitter Grid.Column="1"></GridSplitter>
        <StackPanel Grid.Column="2">
            <ListBox Name="lbFiles" 
                     ItemsSource="{Binding Mode=TwoWay, ElementName=lbDeployments, Path=SelectedItem.InnerText, UpdateSourceTrigger=PropertyChanged}" 
                     ItemTemplate="{StaticResource dtFiles}"
                     Height="400"></ListBox>
        </StackPanel>
    </Grid>
</Window>

XML:

<?xml version="1.0" encoding="utf-8"?>
<Deployments MostRecentDate="12/31/2009 8:41:13 PM">
    <Filters>
        <Filter>.cs</Filter>
        <Filter>.csproj</Filter>
    </Filters>
    <Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM">
        <File>file1.cs</File>
        <File>file2.cs</File>
    </Deployment>
    <Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM">
        <File>file1.cs</File>
        <File>file2.cs</File>
    </Deployment>
    <Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM">
        <File>file1.cs</File>
        <File>file2.cs</File>
    </Deployment>
    <Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM">
        <File>file1.cs</File>
        <File>file2.cs</File>
    </Deployment>
    <Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM">
        <File>file1.cs</File>
        <File>file2.cs</File>
    </Deployment>
</Deployments>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:32:48+00:00Added an answer on May 11, 2026 at 11:32 pm

    Data bindings are tough because they tend to fail silently, which makes them very hard to debug. The number one issue that you had in your code was a misspelling of the ElementName on the lbFiles ListBox. Misspellings will get you every time! I was able to get the File names to appear after correcting the spelling mistake, removing the innerText portion of the binding, and removing the ItemTemplate. I’m not sure why the ItemTemplate wasn’t working, but hopefully this example will get you moving again.

    <Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="600" Width="800">
    <Window.Resources>
        <XmlDataProvider x:Key="AllDeployments" XPath="Deployments" Source="Deployments.xml" />
        <DataTemplate x:Key="dtDeployments">
            <StackPanel FlowDirection="LeftToRight" Orientation="Horizontal">
                <TextBlock Text="{Binding XPath=@Name}" />
                <TextBlock Text=" - "/>
                <TextBlock Text="{Binding XPath=@Date}" />
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="dtFiles">
            <TextBlock Text="{Binding XPath=File}" />
        </DataTemplate>
    </Window.Resources>
    <Grid Name="gMain">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="2"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Menu Grid.Column="0" Grid.ColumnSpan="3"></Menu>
        <ListBox Grid.Column="0" Name="lbDeployment" 
                 ItemsSource="{Binding Source={StaticResource AllDeployments}, XPath=Deployment}"
                 ItemTemplate="{StaticResource dtDeployments}"></ListBox>
        <GridSplitter Grid.Column="1"></GridSplitter>
        <StackPanel Grid.Column="2">
            <ListBox Name="lbFiles" 
                     ItemsSource="{Binding ElementName=lbDeployment, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged}"                      
                     Height="400" />
        </StackPanel>
    </Grid>
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.