When a ValueConverter is used as part of a binding, one of the parameters to the Convert
function is a System.Globalization.CultureInfo
object.
Can anyone tell me where this culture object gets its info from?
I have some code that formats a date based on that culture. When i access my silverlight control which is hosted on my machine, it formats the date correctly (using the d/MM/yyyy format, which is set as the short date format on my machine). When i access the same control hosted on a different server (from my client machine), the date is being formatted as MM/dd/yyyy hh:mm:ss - which is totally wrong. Coincidentally the regional settings on the server are set to the same as my client machine.
This is the code for my value converter:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DateTime)
{
if (parameter != null && !string.IsNullOrEmpty(parameter.ToString()))
return ((DateTime)value).ToString(parameter.ToString());
else
return ((DateTime)value).ToString(culture.DateTimeFormat.ShortDatePattern);
}
return value;
}
basically, a specific format can be specified as the converter parameter, but if it isn't then the short date pattern of the culture object is used.
Edit: alright, i've worked out the issue - the version of the silverlight control on the server was an old version. Duh. The developer responsible (that would be me :) has been instructed to give himself a slap around the ears for his retarded mistake, and is currently considering having a beer with his lunch because it may enhance his c0d1ng sk1llz for the rest of the day.
Thanks to those who took the time to answer though :)