0
我正在创建WPF中的消息应用程序的过程中,作为其中的一部分,我有一个列表框,显示当前可用的作者标题和名称的所有消息。无论如何,我目前正在发展,但我希望展示的数据并没有出现,但标题做(作者:和标题:)。请注意,我的XML文件是一个测试,我知道来自另一个项目,我在网上看过。问题与WPF DataBinding到XML文件
任何帮助,将不胜感激谢谢。
XAML的数据绑定和的ItemsSource模板:
<XmlDataProvider x:Key="Announcement" Source="Data/People.xml" XPath="People"/>
<DataTemplate x:Key="AnnouncementTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Author: " FontWeight="Bold"/>
<TextBlock>
<TextBlock.Text>
<Binding XPath="./ImageFile"/>
</TextBlock.Text>
</TextBlock>
<TextBlock Text="Title: " FontWeight="Bold"/>
<TextBlock Text="{Binding XPath=./Notes/}"/>
</StackPanel>
</DataTemplate>
<ListBox Style="{StaticResource SpecialListStyle}"
Name="listBox1"
Grid.Row="1"
Margin="10,10,10,10"
IsSynchronizedWithCurrentItem="True"
SelectedIndex="0"
ItemContainerStyle="{StaticResource SpecialListItem}"
Foreground="Black"
ItemsSource="{Binding Source={StaticResource Announcement}, XPath=Person}"
ItemTemplate="{StaticResource AnnouncementTemplate}"/>
XML文件:
<?xml version="1.0" encoding="utf-8" ?>
<People>
<Person Name="Capt. Monterey Jack">
<ImageFile>Data/MontereyJack.jpg</ImageFile>
<Notes>The Captain loves his cheese, but hates milk.</Notes>
</Person>
<Person Name="Dr. Disco Fortuna">
<ImageFile>Data/DiscoFortuna.jpg</ImageFile>
<Notes>He disco dances when he's not selling organic vacuum filters.</Notes>
</Person>
<Person Name="Professor Huunkel Froobenhammer">
<ImageFile>Data/HuunkelFroobenhammer.jpg</ImageFile>
<Notes>Huunkel designed a better mousetrap, but lost the blueprint.</Notes>
</Person>
</People>