XAMLとWPFでのデータバインディングに問題があります。具体的には、XmlDataProviderからListBoxにデータをバインドしようとしています。
問題は、これです。VisualStudio 2010でデザインモードを使用している場合、xmlアイテムは正しく表示されますが、アプリを実行するとリストボックスが空になります。
これが私のxamlの外観です。私はコードビハインドを使用していないので、これですべてです。
<Window x:Class="WpfTest9_Binding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="309" Width="622">
<Window.DataContext>
<XmlDataProvider XPath="Servers">
<x:XData>
<Servers>
<Server name="Server01" active="true" />
<Server name="Server02" active="false" />
<Server name="Testserver01" active="true" />
<Server name="Testserver02" active="true" />
</Servers>
</x:XData>
</XmlDataProvider>
</Window.DataContext>
<Grid>
<ListBox ItemsSource="{Binding XPath=*}" Margin="12">
<ListBox.ItemTemplate>
<DataTemplate>
<Border CornerRadius="5" Margin="5" BorderThickness="2" BorderBrush="#FFC14343">
<StackPanel Orientation="Horizontal" Margin="5">
<CheckBox IsChecked="{Binding XPath=@active}" />
<Label Content="{Binding XPath=@name}" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
上で述べたように、奇妙なことに、デザインモードでは機能しているように見えますが、アプリケーションを実行するとリストボックスがいっぱいになりません。エラーメッセージや警告も表示されません。
どうしたの?