I want to bind XML file to a ListBox. The problem is that items in ListBox doesn't show up after binding it to an XML file.
I've set ItemsSource in ListBox to StaticResource but it doesn't work, it doesn't show up in Visual Studio's Designer or in app itself.
Here's XAML code:
<Window x:Class="StudyNotes.ModifySubjectListWindow"
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:StudyNotes"
mc:Ignorable="d"
Title="" Height="150" Width="300" ResizeMode="NoResize">
<Grid>
<Grid.Resources>
<XmlDataProvider x:Key="SubjectData" Source="SubjectList.xml" XPath="/Subjects/Subject"/>
</Grid.Resources>
<DockPanel Margin="10">
<StackPanel DockPanel.Dock="Right" Margin="10,0,0,0">
<Button Name="AddSubjectButton" Margin="0,0,0,5">Add</Button>
<Button Name="DeleteSubjectButton">Delete</Button>
</StackPanel>
<ListBox x:Name="SubjectList" ItemsSource="{Binding Source={StaticResource SubjectData}, XPath=/Subjects/Subject}"></ListBox>
</DockPanel>
</Grid>
</Window>
Here's XML document:
<?xml version="1.0" encoding="utf-8" ?>
<Subjects>
<Subject Name="Subject1"/>
<Subject Name="Subject2"/>
<Subject Name="Subject3"/>
<Subject Name="Subject4"/>
</Subjects>
I expected this to be working and showing up, but there's definitely something wrong that I have no idea of.