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?
Ihre 'AncestorType = {x: Typ local: Mainwindow}' ist höchstwahrscheinlich vom Typ 'Window' statt' MainWindow' – lokusking