Hello,
I've got a problem with the datagrid field format property. I want to display the time in non 24h format like "02:35:56 AM". I set the format to "hh:mm:ss tt" but this does not work. Did i make any mistake?
XAML:
<Custom:XamDataGrid DataSource="{Binding Data}"> <Custom:XamDataGrid.FieldLayouts> <Custom:FieldLayout> <Custom:Field Format="hh:mm:ss tt" Label="Zeit" IsReadOnly="True" AlternateBinding="{Binding Date}">
</Custom:Field > </Custom:FieldLayout> </Custom:XamDataGrid.FieldLayouts> </Custom:XamDataGrid>
I added a test solution...
Thanks
Andreas
Hello Andreas,
Thank you for the sample application you have provided.
I tested the application and the XamDataGrid seems to display the Date property for every DataItem in a 12 hour format correctly. I have attached an image that shows how the data in code-behind is in a 24 hour format and the XamDataGrid displays it in a 12 hour format.
24h format: Format="HH:mm:ss tt"12h format: Format="hh:mm:ss tt"
Are you noticing a behavior that is different from the one I have mentioned above? If so, can you please provide more details on the issue?
Please note that in the case of the application you have provided, it is unnecessary to use an AlternateBinding since the DateTime instance is placed directly in the DataItem class and we can use a simple name binding which could provid a better performance.
<Custom:Field Format="hh:mm:ss tt" Label="Zeit" IsReadOnly="True" Name="Date">
In addition, you can use the DateTimeField for displaying DateTime data. In this case the XamDataGrid will automatically set the necessary settings for displaying the data and additional DateTime settings will be available.
<Custom:DateTimeField ... ></Custom:DateTimeField>
If you have any questions, please let me know.
The behavior at my application is different. Please set the culture to:
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
The culture of my application is not in every case "en-US". If i set the culture to "en-US" the output looks like yours.
At the test solution alternate binding is not neccessary but in the application who i create it is.
Thanks.
Thank you for the feedback.
Presuming that you are referring to the issue in regards to the missing AM/PM identifier, please note that it is available for the "en-US" culture only.
In order to apply the AM/PM identifier when the culture is set to german, I can suggest you create a converter for the respective field by returning the DateTime value as a string representation with the "en-US" culture.
public class TimeConverter : IValueConverter{ public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return (value != null) ? ((DateTime)value).ToString(@"hh:mm:ss tt", new CultureInfo("en-US")) : Binding.DoNothing; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); }}
I have modified the sample application you have provided by demonstrating the approach from above.