View:
I want to format the Date to \"dd/MM/yyyy\", in other words, without the time.
I
There is no property named StringFormat in Binding class. You can use Converter and ConverterParameter to do this. You can refer to Formatting or converting data values for display.
For example here, I bind the date of a DatePicker to the text of a TextBlock.
XAML:
code behind, the DateFormatter class:
public class DateFormatter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var a = language;
// Retrieve the format string and use it to format the value.
string formatString = parameter as string;
if (!string.IsNullOrEmpty(formatString))
{
return string.Format(formatString, value);
}
return value.ToString();
}
// No need to implement converting back on a one-way binding
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return DependencyProperty.UnsetValue;
}
}