Binding XML to Listbox in WPF
Before I give up and start from scratch, probably from a XML data island which seems simplier (see here: http://www.longhorncorner.com/UploadFile/cook451/DataBindingXAML12102005134820PM/DataBindingXAML.aspx ) is there anyway I can change a few parameters in the code below and make it work? It compiles but the Listbox does not show anything.
I've tried dozens of variations, some of which do not compile
RC
// appears in App.xaml<Application.Resources>
<XmlDataProvider x:Key="LearnWPFeed" Source="Products3.xml" XPath="/Products3/Product3" /></Application.Resources>
// appears in window (a grid having four rows and two columns, with the listbox in the last row and first column):<Grid x:Name="myGrid30" Grid.Row="3" Grid.Column="0" Margin="1" DataContext="{StaticResource LearnWPFeed}" >
<StackPanel>
<ListBox x:Name="lstBox30" Margin="4" HorizontalAlignment="Stretch" >
<StackPanel Orientation="Horizontal" >
<TextBlock FontWeight="Bold">Name</TextBlock>
<TextBox HorizontalAlignment="Stretch" Text="{Binding XPath=@ModelName}" ></TextBox>
<TextBlock Text="{Binding XPath=@ProductImagePath}" ></TextBlock>
</StackPanel>
</ListBox>
</StackPanel>
</Grid>// appears in Solution Explorer as a Resource
<Products3>
<Product3>
<Datetime>2:06:52 PM</Datetime>
<ModelNumber>100</ModelNumber>
<ModelName>MyModelName</ModelName>
<ProductImagePath>myPathHere</ProductImagePath>
<GuidNumber>0f5efb12-03d5-4a78-8b49-f988d5cc1767</GuidNumber>
<Description>Description Here </Description>
</Product3>
<Product3>
<Datetime>2:06:51 PM</Datetime>
<ModelNumber>101</ModelNumber>
<ModelName>MyModelName2</ModelName>
<ProductImagePath>myPathHere2</ProductImagePath>
<GuidNumber>0f5efb12-03d5-4a78-8b49-f988d5cc1768</GuidNumber>
<Description>Description Here2 </Description>
</Product3>
</Products3>
Answers
- I've decided to do one of two things: either switch to an inline XML 'data island', or, read the XML file on loadup using traditional XML techniques and then insert each node into a List, and point your controls to the list.
That is easier.
RC- Marked As Answer byRonConger09 Saturday, November 07, 2009 3:39 PM
All Replies
- I've decided to do one of two things: either switch to an inline XML 'data island', or, read the XML file on loadup using traditional XML techniques and then insert each node into a List, and point your controls to the list.
That is easier.
RC- Marked As Answer byRonConger09 Saturday, November 07, 2009 3:39 PM

