Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF XML DataBinding
    text
    copied!<p>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.</p> <p>XAML:</p> <pre><code>&lt;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"&gt; &lt;Window.Resources&gt; &lt;XmlDataProvider x:Key="AllDeployments" XPath="Deployments" Source="Deployments.xml" /&gt; &lt;DataTemplate x:Key="dtDeployments"&gt; &lt;StackPanel FlowDirection="LeftToRight" Orientation="Horizontal"&gt; &lt;TextBlock Text="{Binding XPath=@Name}" /&gt; &lt;TextBlock Text=" - "/&gt; &lt;TextBlock Text="{Binding XPath=@Date}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="dtFiles"&gt; &lt;TextBlock Text="{Binding XPath=File}" /&gt; &lt;/DataTemplate&gt; &lt;/Window.Resources&gt; &lt;Grid Name="gMain"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition /&gt; &lt;ColumnDefinition Width="2"/&gt; &lt;ColumnDefinition /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Menu Grid.Column="0" Grid.ColumnSpan="3"&gt;&lt;/Menu&gt; &lt;ListBox Grid.Column="0" Name="lbDeployment" ItemsSource="{Binding Source={StaticResource AllDeployments}, XPath=Deployment}" ItemTemplate="{StaticResource dtDeployments}"&gt;&lt;/ListBox&gt; &lt;GridSplitter Grid.Column="1"&gt;&lt;/GridSplitter&gt; &lt;StackPanel Grid.Column="2"&gt; &lt;ListBox Name="lbFiles" ItemsSource="{Binding Mode=TwoWay, ElementName=lbDeployments, Path=SelectedItem.InnerText, UpdateSourceTrigger=PropertyChanged}" ItemTemplate="{StaticResource dtFiles}" Height="400"&gt;&lt;/ListBox&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Deployments MostRecentDate="12/31/2009 8:41:13 PM"&gt; &lt;Filters&gt; &lt;Filter&gt;.cs&lt;/Filter&gt; &lt;Filter&gt;.csproj&lt;/Filter&gt; &lt;/Filters&gt; &lt;Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM"&gt; &lt;File&gt;file1.cs&lt;/File&gt; &lt;File&gt;file2.cs&lt;/File&gt; &lt;/Deployment&gt; &lt;Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM"&gt; &lt;File&gt;file1.cs&lt;/File&gt; &lt;File&gt;file2.cs&lt;/File&gt; &lt;/Deployment&gt; &lt;Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM"&gt; &lt;File&gt;file1.cs&lt;/File&gt; &lt;File&gt;file2.cs&lt;/File&gt; &lt;/Deployment&gt; &lt;Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM"&gt; &lt;File&gt;file1.cs&lt;/File&gt; &lt;File&gt;file2.cs&lt;/File&gt; &lt;/Deployment&gt; &lt;Deployment Name="First Deployment" ID="1" Date="6/29/2009 8:41:13 PM"&gt; &lt;File&gt;file1.cs&lt;/File&gt; &lt;File&gt;file2.cs&lt;/File&gt; &lt;/Deployment&gt; &lt;/Deployments&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload