If I had a non-anonymous class like this, I know I can use DisplayNameAttribute like this.
class Record{
[DisplayName("The Foo")]
public string Foo {get; set;}
[DisplayName("The Bar")]
public string Bar {get; set;}
}
but I have
var records = (from item in someCollection
select{
Foo = item.SomeField,
Bar = item.SomeOtherField,
}).ToList();
and I use records for DataSource for a DataGrid. The column headers show up as Foo and Bar but they have to be The Foo and The Bar. I cannot create a concrete class for a few different internal reasons and it will have to be an anonymous class. Given this, is there anyway I can set DisplayNameAttrubute for members of this anonymous class?
I tried
[DisplayName("The Foo")] Foo = item.SomeField
but it won’t compile.
Thanks.
How about the following solution:
Then you have the following Attached Property code: