Thursday, 21 November 2013

DateTimeFormatterConverter for WinRT

With there being no StringFormat on a binding in WinRT yet you can use this converter to leverage the crazy (different) DateTimeFormatter object:

    public class DateTimeFormatterConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, string language)
var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter(parameter.ToString());
return formatter.Format((DateTime)value);

public object ConvertBack(object value, Type targetType, object parameter, string language)
throw new NotImplementedException();


<converters1:DateTimeFormatterConverter x:Key="DateTimeFormatterConverter" />

<TextBlock Text="{Binding DealDate,
Converter={StaticResource DateTimeFormatterConverter},
ConverterParameter=day month year}"

1 comment:

  1. You make some great points and I don't think I could have made them any better. Thanks for the good information you have shared here.