我在 WPF 中有一个 DataGrid 并用如下数据填充它:
public enum Sharing
{
Equal,
SurfaceBased,
}
public class Data
{
public bool Active { get; set; }
public string Name { get; set; }
public int Floor { get; set; }
public Sharing Sharing { get; set; }
}
public ObservableCollection<Data> _col = new ObservableCollection<Data>()
{
new Data(){Active = true, Name = "KRL", Floor = 0 },
new Data(){Name = "DAT", Floor = 1},
new Data(){Name = "TRE", Floor = 1},
new Data(){Name = "DUO", Floor = 2},
};
public MainWindow()
{
InitializeComponent();
grid.AutoGenerateColumns = true;
grid.DataContext = _col;
grid.ItemsSource = _col;
}
我想知道是否可以在枚举和 POCO 类上使用一些属性,以便 DataGrid 在标题和 ComboCoxes 上显示它们(而不是变量名)。
像这样的东西:
public enum Sharing
{
[Name("This is a test")]
Equal,
[Name("This is a test 2")]
SurfaceBased,
}
这可能吗?