I'm trying to write a new application in VB.net and WPF for our internal support team to use in troubleshooting common customer issues. It's basically a treeview on the left side of the screen, with a document viewer on the right. The Goal is to have it so when someone clicks a topic on the left, it loads an XPS document into the viewer on the right.
Originally, I was going to hardcode values into the program for topics to be covered, but that would mean I'd have to recompile the code every time I wanted to add new topics, or someone submitted something to add. I decided to try looking at XML as a solution, so that the TreeView values could be pulled from a file, making everything external to the application.
I've got it semi working...except for one major problem...the treeview only seems to populate the very first node in the XML, not all of them. Here is what I've got so far.
As it sits right now, the only thing that shows in the treeview box is "Sr-650-101" which is the first "Item" in my XML file. What am I doing wrong that prevents it from populating both (and ultimately other) xml items? The XML file was a sample I got somewhere, I replaced the Item names with 2 items I wanted to add, will need to change the City items to the sub-topics and XPS locations I want to use later, but for now I'd like to get the items to all load.
Question
SirEvan
I'm trying to write a new application in VB.net and WPF for our internal support team to use in troubleshooting common customer issues. It's basically a treeview on the left side of the screen, with a document viewer on the right. The Goal is to have it so when someone clicks a topic on the left, it loads an XPS document into the viewer on the right.
Originally, I was going to hardcode values into the program for topics to be covered, but that would mean I'd have to recompile the code every time I wanted to add new topics, or someone submitted something to add. I decided to try looking at XML as a solution, so that the TreeView values could be pulled from a file, making everything external to the application.
I've got it semi working...except for one major problem...the treeview only seems to populate the very first node in the XML, not all of them. Here is what I've got so far.
TreeItems.xml XML file:
<?xml version="1.0" encoding="utf-8" ?> <Items> <Item ItemName="SR-650-101"> <City CityName="Berlin" Uri="http://en.wikipedia.org/wiki/Berlin" /> <City CityName="Hamburg" Uri="http://en.wikipedia.org/wiki/Hamburg" /> <City CityName="Munich" Uri="http://en.wikipedia.org/wiki/Munich" /> <City CityName="Stuttgart" Uri="http://en.wikipedia.org/wiki/Stuttgart" /> </Item> <Item ItemName="SR-650-103"> <City CityName="Berlin" Uri="http://en.wikipedia.org/wiki/Berlin" /> <City CityName="Hamburg" Uri="http://en.wikipedia.org/wiki/Hamburg" /> <City CityName="Munich" Uri="http://en.wikipedia.org/wiki/Munich" /> <City CityName="Stuttgart" Uri="http://en.wikipedia.org/wiki/Stuttgart" /> </Item> </Items>Section of WPF Xaml code that sets the xml file as the data provider:
<Window.Resources> <XmlDataProvider x:Key="TreeItems" XPath="Items/Item" Source="C:\TreeItems.xml"/> </Window.Resources>and section of code that sets the treeview's datasource:
<TreeView Grid.Column="1" Margin="47,139,45,203" Name="TreeView2" ItemsSource="{Binding Source={StaticResource TreeItems}, XPath=@ItemName}" />As it sits right now, the only thing that shows in the treeview box is "Sr-650-101" which is the first "Item" in my XML file. What am I doing wrong that prevents it from populating both (and ultimately other) xml items? The XML file was a sample I got somewhere, I replaced the Item names with 2 items I wanted to add, will need to change the City items to the sub-topics and XPS locations I want to use later, but for now I'd like to get the items to all load.
Thanks in advance.
Link to comment
Share on other sites
0 answers to this question
Recommended Posts