I have a simple object like:
class Item
{
....
public String Measure { get; set; }
public String[] Measures {get; }
}
Which I am trying to bind to a DataGrid with two text columns and a combo box column.
For the combo box column, property Measure is the current selection and Measures the possible values.
My XAML is:
<DataGrid Name="recipeGrid" AutoGenerateColumns="False"
CellEditEnding="recipeGrid_CellEditEnding" CanUserAddRows="False"
CanUserDeleteRows="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Food" Width="Auto"
Binding="{Binding Food.Name}" />
<DataGridTextColumn Header="Quantity" IsReadOnly="False"
Binding="{Binding Quantity}" />
<DataGridComboBoxColumn Header="Measure" Width="Auto"
SelectedItemBinding="{Binding Path=Measure}"
ItemsSource="{Binding Path=Measures}" />
</DataGrid.Columns>
</DataGrid>
The text column are displayed just fine but the combobox is not - the values are not displayed at all. The binding error is:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Measures; DataItem=null; target element is 'DataGridComboBoxColumn' (HashCode=11497055); target property is 'ItemsSource' (type 'IEnumerable')
How do I fix this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…