我已将以下模型类设置为DataGrid
的来源:
public class AttributesModel
{
public string Field { get; private set; }
[Display(Name = "Sort Order")]
public SortOrder SortBy { get; set; }
[Display(Name = "Group By")]
public string GroupBy { get; set; }
[Display(Name = "Having")]
public string Having { get; set; }
[Display(Name = "Display Order")]
public string DisplayOrder { get; set; }
[Display(Name = "Aggregate By")]
public Aggregate AggregateBy { get; set; }
public enum Aggregate
{
None,
Sum,
Minimum,
Maximum,
Average
}
public enum SortOrder
{
Unsorted,
Ascending,
Descending
}
public AttributesModel(string field)
{
Field = field;
}
}
我基本上是尝试使用上面的prpoerties绑定我的DataGrid中的列。除了为组合框列设置的enums
之外,它们都有效。
我似乎无法将组合框绑定。这就是我尝试过的:
<DataGridComboBoxColumn Width="Auto" CanUserResize="False" CanUserReorder="False" CanUserSort="False" IsReadOnly="False" ItemsSource="{Binding ElementName=AttributesWindow, Path=SortOrder}">
<DataGridComboBoxColumn.Header>Order</DataGridComboBoxColumn.Header>
</DataGridComboBoxColumn>
答案 0 :(得分:2)
ItemsSource期望IEnumerable
值,enum
不是IEnumerable
。试试这个:
public IEnumerable<SortOrder> SortOrderList
{
get { return Enum.GetValues(typeof(SortOrder)).Cast<SortOrder>(); }
}