Hi,
I am trying to come up with some generic way to apply Data Annotation attribute StringFormat to XAML:
[DisplayFormat(DataFormatString = "MM-dd-yyyy")]public DateTime? Date { get; set; }
It does not work automatically. For regular data grid I can do this:
private void gridMessages_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { DataGridBoundColumn obj = e.Column as DataGridBoundColumn; var attrs = Attribute.GetCustomAttributes(typeof(TestMessage).GetProperty(e.PropertyName)); var attr = attrs.FirstOrDefault(a => a is DisplayFormatAttribute) as DisplayFormatAttribute; if (obj != null && obj.Binding != null && attr != null && string.IsNullOrEmpty(obj.Binding.StringFormat)) { obj.Binding.StringFormat = attr.DataFormatString; } }
But xamGrid does not have AutoGeneratingColumn event.
Any suggestion how to insert DataFormatString into data binding for xamGrid.
Or even better, maybe xamGrid can use somehow data annotation attributes on data model for data formating?
Thanks.
Vic
If you are using a TextColumn there is a FormatString off othe column which can be used to format the string displayed.
Thanks for reply.
I have AutoGenerateColumns="True" - don't set up columns myself.
and in addition to this I am more concerned about numeric data types.