I use the following XAML file to create an XML resource and then bind this resource to a listbox:
<Window x:Class="WpfPractice.HierarchicalData"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="HierarchicalData" Height="200" Width="650">
<Window.Resources>
<XmlDataProvider x:Key="XMLItems" XPath="/colors/color/@name">
<x:XData>
<colors >
<color name="pink"/>
<color name="white"/>
<color name="black"/>
</colors>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding Source={StaticResource XMLItems}}"/>
</Grid>
</Window>
VS designer displays the list of colours without any problems, but when I debug the WPF application the window is empty. In fact I have the same problem when I try to bind any XML items to WPF controls. Any suggestions why?
Thanks!
You should reset the default namesapce:
MSDN: