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>