0

I've got the following model class set as the source of my 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;
        }
    }

I'm basically trying to bind the columns in my DataGrid, with the prpoerties above. They all work except for the enums which are set up for the combo box columns.

I cannot seem to get the comboboxes to bind. This is what I've tried:

<DataGridComboBoxColumn Width="Auto" CanUserResize="False" CanUserReorder="False" CanUserSort="False" IsReadOnly="False" ItemsSource="{Binding ElementName=AttributesWindow, Path=SortOrder}">
                    <DataGridComboBoxColumn.Header>Order</DataGridComboBoxColumn.Header>
                </DataGridComboBoxColumn>
4

1 回答 1

2

ItemsSource 需要一个IEnumerable值,enum不是IEnumerable。尝试这个:

public IEnumerable<SortOrder> SortOrderList
{
    get { return Enum.GetValues(typeof(SortOrder)).Cast<SortOrder>(); }
}
于 2012-10-26T20:27:39.407 回答