如何在xaml中获取系统时间格式 [英] How to get system time format in xaml

查看:93
本文介绍了如何在xaml中获取系统时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想用系统时间格式创建datagrid单元格模板。时间格式应根据系统设置显示12/24格式。是否可以在xaml中获得系统时间格式。



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.

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

                    HorizontalAlignment="Right" />
</DataTemplate>





更新:



Update:

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.

推荐答案

可能不是确切的您正在寻找的解决方案,但作为解决方案,您可以考虑它。



使用C#在代码中查找系统短时格式,然后格式化数据相应的数据源然后绑定数据网格。



查看此链接以获取有关使用C#查找系统时间格式的帮助 -

DateTimeFormatInfo.ShortTimePattern属性 [ ^ ]



希望,它有帮助:)
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 :)


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


这篇关于如何在xaml中获取系统时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆