2017-09-14 8 views
0

ListBoxがあり、それがMyObject.MyCollectionにバインドされている場合、どうすればMyObject.MyValueを得ることができますか?ListBoxコレクションの外部のバインディングプロパティ

<ListBox ItemsSource="{Binding Path=MyObject.MyCollection}"> 
    <ListBox.ItemTemplate> 
    <DataTemplate> 
     <StackPanel> 
     <TextBlock Text="{Binding Path=Name}"/> 
     <TextBlock Text="{Binding Path=MyObject.MyValue}"/> 
     </StackPanel> 
    </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

public class MyObject { 
    public ObservableCollection<CollectionThing> MyCollection {get; set;} 
    public string MyValue {get; set;} 
} 

答えて

0

私はあなたが結合

<ListBox ItemsSource="{Binding Path=MyObject.MyCollection}"> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel> 
       <TextBlock Text="{Binding Path=Name}"/> 
       <TextBlock Text="{Binding Path=DataContext.MyObject.MyValue, 
            RelativeSource={RelativeSource AncestorType=ListBox}}"/> 
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
の相対的なソースを使用することができると思う