Monday, 29 September 2014

Trying to populate a combobox in winrt xaml from xml file



I'm trying to populate a drop down with data from an xml file I'm sure I'm close because intellisense shows data out of the XML file but when I try to bind it to the combobox I get each entry that has the type of data but not the data.



public void PopPrograms()
{
//string picprgrmsXMLPath = Path.Combine(Package.Current.InstalledLocation.Path, "Assets/PicPrograms.xml");
string picprgrmsXMLPath = Path.Combine(Windows.Storage.ApplicationData.Current.RoamingFolder.Path, "PicPrograms.xml");
//string picprgrmsXMLPath = @"C:\temp\PicPrograms.xml";
XDocument loadedData = XDocument.Load(picprgrmsXMLPath);

var data = from query in loadedData.Descendants("Node")
select new PicPrograms
{
//ProgramID = (string)query.Element("pID"),
ProgramName = (string)query.Element("pName"),
};
cbProgram.ItemsSource = data;


and now here is my xaml:



<ComboBox x:Name="cbProgram" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="55,115,0,0" VerticalAlignment="Top" Width="215" Height="32" SelectionChanged="cbProgram_SelectionChanged" Grid.RowSpan="2"/>


I'm sure I'm missing something here but just don't know what it is.


Here is a snippet of the xml doc:



<Programs>
<Node>
<pID>9930FA1A-A59E-4F78-8AFF-2E07AD4C1CD8</pID>
<pName>Black and Gold</pName>
</Node>
<Node>
<pID>23B4263C-4BF2-4EC3-AD99-17BCD6301189</pID>
<pName>Darren Hawkins Pic Review</pName>
</Node>


The resulting combobox shows the same thing for each element: "CameraCapture.CapturePhoto+PicProgram"


No comments:

Post a Comment