2017-09-14 1 views
0

Wenn ich eine ListBox habe und es an MyObject.MyCollection gebunden ist, wie kann ich auch MyObject.MyValue bekommen?Binding Eigenschaften außerhalb ListBox Sammlung

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

Antwort

0

Ich glaube, Sie Relative Quelle in der Bindung

<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> 
verwenden können
Verwandte Themen