Scott Starks

Scott Starks

  • NA
  • 11
  • 558

Unable to bind/populate combobox to xml file

Apr 13 2018 12:35 PM

Here is my xml file called AvailableTestsXMLFile2.xml.  I have added this file to my project.

 

<?xml version="1.0" encoding="utf-8"?>

    <AvailableTests>

         <Test name="high voltage" testNumber="1" />

         <Test name="low voltage" testNumber="2" />

         <Test name="new test" testNumber="3" />

         <Test name="old test" testNumber="4" />

    </AvailableTests>

   

        

        

        

        

   

Here is my xaml (I am not getting anything in my combobox called testNameBox)...

<Window x:Class="WpfTester.MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:local="clr-namespace:WpfTester"

mc:Ignorable="d"

Title="MainWindow" Height="450" Width="800">

<Window.Resources>

<XmlDataProvider x:Key="AvailableTests" Source="AvailableTestsXMLFile2.xml" XPath="AvailableTests"/>

</Window.Resources>

<StackPanel Orientation="Vertical" MaxWidth="500" HorizontalAlignment="Left">

<Grid>

<Image HorizontalAlignment="Left" VerticalAlignment="Top" Source="C:\Users\StarkS02\Pictures\abbott-logo.jpg" Height="72" Width="72"/>

</Grid>

<Border Background="DeepSkyBlue" BorderThickness="2" BorderBrush="Black" CornerRadius="10" Margin="10" Width="450" Height="85">

<StackPanel>

<TextBlock>Configuration Section</TextBlock>

</StackPanel>

</Border>

<Border Background="DeepSkyBlue" BorderThickness="2" BorderBrush="Black" CornerRadius="10" Margin="10">

<StackPanel>

<TextBlock>Select Test</TextBlock>

<StackPanel Orientation="Horizontal">

<ComboBox x:Name="testNameBox" IsReadOnly="True" HorizontalAlignment="Left" IsEditable="False" ItemsSource="{Binding Source={StaticResource AvailableTests}, XPath=./AvailableTests/Test/name}" Margin="10 10 10 10" DisplayMemberPath="Test/name*" Text="name" DataContext="name">

</ComboBox>

<ComboBox x:Name="testSelectedBox" IsReadOnly="False" HorizontalAlignment="right" IsEditable="False" Margin="10 10 10 10">

</ComboBox>

</StackPanel>

<CheckBox Name="ChkRepeatTilFailure" Foreground="White" Content="Repeat Test Until Failure" Margin="5 5 5 5"/>

<StackPanel Orientation="Horizontal">

<Image HorizontalAlignment="Left" VerticalAlignment="Top" Source="C:\Users\StarkS02\Pictures\play.png" Height="42" Width="42"/>

<Image HorizontalAlignment="Left" VerticalAlignment="Top" Source="C:\Users\StarkS02\Pictures\pause.jpg" Height="42" Width="42"/>

<Image HorizontalAlignment="Left" VerticalAlignment="Top" Source="C:\Users\StarkS02\Pictures\stop.png" Height="42" Width="42"/>

</StackPanel>

<Button Content="Submit Test" Margin="4 4 4 4" Width="65"/>

</StackPanel>

</Border>

<Border Background="DeepSkyBlue" BorderThickness="2" BorderBrush="Black" CornerRadius="10" Margin="10" Height="65">

<StackPanel>

<TextBlock>Test Response Section</TextBlock>

<TextBox Text="Test 3 Successful!" />

</StackPanel>

</Border>

</StackPanel>

</Window>

 

 Any ideas on what I need to do to load the combobox correctly?  Thanks, Scott