2016-06-30 9 views
0

Ich versuche, diese Combo zu binden:Binding Kombinationsfeld aus dem Hauptfenster Ressourceneigenschaft ItemSource

<ComboBox ItemsSource="{Binding StudentStudyPointsList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}}"> 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <TextBlock Text="{Binding Number}"/> 
       <TextBlock Text=" - "/> 
       <TextBlock Text="{Binding Title}"/> 
      </StackPanel> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 

Der Fehler:

System.Windows.Data Error: 40 : BindingExpression path error:

'StudentStudyPointsList' property not found on 'object' ''MainWindow' (Name='')'. BindingExpression:Path=StudentStudyPointsList;

DataItem='MainWindow' (Name=''); target element is 'ComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')

Das Objekt öffentlich in der Hauptansicht Modell definiert:

public List<StudyPointItem> StudentStudyPointsList { get; set; } 

und das Hauptfenster hat dieses Datacontext:

<Window.DataContext> 
    <local:OCLMEditorModelView/> 
</Window.DataContext> 

Wie bekomme ich die Combo, um die Itemsource korrekt zu binden?

+0

Ihre 'AncestorType = {x: Typ local: Mainwindow}' ist höchstwahrscheinlich vom Typ 'Window' statt' MainWindow' – lokusking

Antwort

0

ich brauchte:

<ComboBox DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}}" 
      ItemsSource="{Binding ReadingStudyPointsList}"> 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Orientation="Horizontal"> 
       <TextBlock Text="{Binding Number}"/> 
       <TextBlock Text=" - "/> 
       <TextBlock Text="{Binding Title}"/> 
      </StackPanel> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 
Verwandte Themen