JD.
JD.

Reputation: 15551

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.

Upvotes: 2

Views: 2410

Answers (2)

Luke Baulch
Luke Baulch

Reputation: 3656

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

Upvotes: 0

Stephen Price
Stephen Price

Reputation: 1649

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;
    }

Upvotes: 4

Related Questions