Skip to content

Instantly share code, notes, and snippets.

@idiotandrobot
Last active August 29, 2015 14:20
Show Gist options
  • Save idiotandrobot/101c1631fc96cf181c4f to your computer and use it in GitHub Desktop.
Save idiotandrobot/101c1631fc96cf181c4f to your computer and use it in GitHub Desktop.
Windows Phone 8.1 StringFormatConverter
public sealed class StringFormatConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null)
return null;
if (parameter == null)
return value;
return string.Format((string)parameter, value);
}
public object ConvertBack(object value, Type targetType, object parameter,
string language)
{
throw new NotImplementedException();
}
}
<StringFormatConverter x:Name="StringFormat"/>
<TextBlock Text="{Binding DateTime, StringFormat=T, RelativeSource={RelativeSource TemplatedParent}}" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment