我有一个模型类,像这样:麻烦填充一个组合框
public class AttributesModel
{
public SortOrder SortBy { get; set; }
public enum SortOrder
{
Unsorted,
Ascending,
Descending
}
public AttributesModel(string field)
{
Field = field;
}
}
,且含有组合框为一列,像这样一个DataGrid:
<DataGridTemplateColumn Width="Auto" IsReadOnly="False" Header="Order">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=AttributesModel}" DisplayMemberPath="SortBy" SelectedValuePath="SortBy" SelectedValue="{Binding Path=AttributesModel}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
类含在DataGrid还具有以下的构造:
DataContext = this;
itemsSource = new ObservableCollection<AttributesModel>(parentDatabaseTable.ListFields.Select(f => new AttributesModel(f)));
出于某种原因,在我的DataGrid中的所有字段都填充组合框除外。请注意,为了简单和易读,我没有在模型类中包含其他字段的代码或DataGrid中的列。他们都成功地填充,除了组合框列。有任何想法吗?
所以它看起来像你绑定'ComboBox'属性'AttributesModel',*不是'IEnumerable',是吗? – McGarnagle
实际上包含在其中的枚举。我也有其他的领域,它没有任何问题。 –