Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I want to create datagrid cell template with system time format. The time format should show 12/24 format base on system settings. Is the any way to get system time format in xaml.

HTML
<DataTemplate x:Key="TimeFieldCellTemplate">
        <TextBlock  Text="{Binding StringFormat=\{0:t\}}"
                    HorizontalAlignment="Right" />
</DataTemplate>


Update:
XML
I found myself in the above data template adding ConverterCulture={x:Static glob:CultureInfo.CurrentCulture} this will take care.

<datatemplate x:key="TimeFieldCellTemplate">
        <textblock text="{Binding StringFormat=\{0:T\},ConverterCulture={x:Static glob:CultureInfo.CurrentCulture}}" horizontalalignment="Right"></textblock>
    </datatemplate>

Note: T= long date format, t= Small date format.
Posted
Updated 25-Nov-15 17:51pm
v2

It may not be the exact solution you are searching for but, as a work-around you may consider it.

Find the system short time format in code behind using C# and then format the data in the datasource accordingly and then bind the datagrid.

Check this link to get help in finding the system time format using C#-
DateTimeFormatInfo.ShortTimePattern Property[^]

Hope, it helps :)
 
Share this answer
 
Comments
hari111r 25-Nov-15 23:52pm    
Thank suvendu, i found the solution using xaml. Please find my update above.
Naz_Firdouse 27-Nov-15 1:13am    
Please post your answer as a solution here and mark as answer so that it will be helpful to others and the question will be in solved list.
C#
Hi I found myself in the above data template adding ConverterCulture={x:Static glob:CultureInfo.CurrentCulture} this will take care.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900