2010-06-29 29 views
0

我想將對象列表綁定到ItemsControl。該對象只有兩個屬性:Movie(一個字符串)和Actors(一個字符串數組)。我可以讓綁定在電影中正常工作。但我無法弄清楚Actors數組的綁定。XAML〜需要綁定語法來收集對象的幫助

<ItemsControl x:Name="MovieList"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Width="100"> 
       <Border Margin="2"> 
        <TextBlock Text="{Binding Movie, Mode=OneWay}" /> 
       </Border> 
       <ListBox ItemsSource="{Binding Actors, Mode=OneWay}"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <TextBlock Text="{Binding}" /> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
      </StackPanel> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <controlsToolkit:WrapPanel /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl> 

有什麼建議嗎?

回答

0
<ListBox ItemsSource="{Binding Actors, Mode=OneWay}"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <TextBlock Text="{Binding}" /> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

這是錯誤的......你必須告訴它你想在演員集合中綁定什麼。

{Binding Path = ActorName}例如...既然你只有一種方法,你可以使用displaymemberpath而不是去:DisplayMemberPath =「ActorName」