I am trying to bind this combo:
<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>
The error:
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')
The property is publicly defined in the main view model:
public List<StudyPointItem> StudentStudyPointsList { get; set; }
And the main window has this DataContext:
<Window.DataContext>
<local:OCLMEditorModelView/>
</Window.DataContext>
How do I get the Combo to bind the itemsource correctly?
Window
instead ofMainWindow
– lokusking