2009-12-14 6 views
0

WPF에서 메시지 응용 프로그램을 만드는 중입니다.이 문서의 일부로 현재 저자 이름 및 이름과 함께 사용 가능한 모든 메시지를 보여주는 목록 상자가 있습니다. 어쨌든 나는 현재 개발 중이지만 내가 보여주고 자하는 데이터는 나타나지 않지만 제목은해야한다. (저자 : and Title :). 필자의 XML 파일은 필자가 온라인에서 본 다른 프로젝트에서 작동하는 테스트입니다.WPF DataBinding to XML 파일과 관련된 문제

감사합니다. 감사드립니다. 데이터 바인딩 및 ItemsSource 템플릿

XAML :

<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> 

답변

2

이 변경되어야합니다

:

<XmlDataProvider x:Key="Announcement" Source="Data/People.xml" XPath="People/Person"/> 

이 변경되어야합니다

<StackPanel Orientation="Horizontal">     
<TextBlock Text="Author: " FontWeight="Bold"/> 
<TextBlock Text="{Binding XPath=ImageFile}" > 
<TextBlock Text="Title: " FontWeight="Bold"/> 
<TextBlock Text="{Binding XPath=Notes}"/> 
</StackPanel>