开发者

Silverlight date format using users locale?

Is there a way to force Silverlight to use the users locale settings when presenting dates in a 开发者_运维知识库datagrid?

JD.


You could use a converter which looks at the System.Globalization.CultureInfo.CurrentCulture

public class SmartDateConverter : IValueConverter {            
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
        DateTime date;
        culture = System.Globalization.CultureInfo.CurrentCulture;
        if (value != null && DateTime.TryParse(value.ToString(), out date))
        {
            string strDate = string.Empty;
            strDate = date.ToString(culture.DateTimeFormat.ShortDatePattern.ToString());
            return strDate;
        }
        return null;
    }


Refer to the answer of this StackOverflow question: How to change date format in Silverlight DatePicker control?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜