次のウィンドウとモデル クラスにバインドされている DataGrid があります。
public partial class AttributesWindow
{
public ObservableCollection<AttributesModel> ItemsSource { get; set; }
private readonly List<string> _fields = new List<string>(new[] { "Test1", "Test2" });
public ObservableCollection<AttributesModel> itemsSource { get; set; }
private DatabaseTable parentDatabaseTable = null;
public AttributesWindow(DatabaseTable parentDatabaseTable)
{
this.parentDatabaseTable = parentDatabaseTable;
InitializeComponent();
DataContext = this;
itemsSource = new ObservableCollection<AttributesModel>(_fields.Select(f => new AttributesModel(f)));
}
}
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;
}
}
何らかの理由で、[Display(Name = "Sort Order")]
プロパティはすべて無視され、DataGrid のヘッダーはプロパティ名を引き継いでいます。
<DataGrid Name="dgAttributes"
ItemsSource="{Binding itemsSource}"
AutoGenerateColumns="True"
CanUserAddRows="False"
CanUserDeleteRows="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserResizeRows="False"
CanUserSortColumns="False"
ColumnWidth="Auto"
>
</DataGrid>