http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.stringformat.aspx
For example, if we apply like this:
<TextBlock Text="{Binding Path=CurrentDate, StringFormat='\{0:MMMM\}', Converter={StaticResource DefaultLowerCaseConverter}}"/>
It would be better if we format within the Converter. In this example, we are converting a date to string in a particular format. We are then formatting the string to lower case.
class DefaultLowerCaseConverter: System.Windows.Data.IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
return ((DateTime) value).ToString("MMMM").ToLower();
}
public object ConvertBack(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
We can use this converter like this:
<TextBlock Text="{Binding Path=CurrentDate, Converter={StaticResource DefaultLowerCaseConverter}}"/>
No comments:
Post a Comment