It turns out there is a very simple solution.
By adding an IValueConverter and using the converter in the binding expression, but ignoring the culture argument, formatting works fine.
You will need one converter (if you do not accept it) for each other format.
Converter (removed the attribute from the sample):
public class DateConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime date = (DateTime)value; return date.ToShortDateString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string strValue = value as string; DateTime resultDateTime; if (DateTime.TryParse(strValue, out resultDateTime)) { return resultDateTime; } return DependencyProperty.UnsetValue; } }
Namespace
xmlns:conv="clr-namespace:Sjofartsverket.LotsPDA20.Client.Converters"
resource
<conv:DateConverter x:Key="dateConverter" />
Expression Binding:
<TextBlock Text="{Binding StartDate, Converter={StaticResource dateConverter}}"
Result: The date is displayed in the correct culture.
source share