I want a specific format in IValueConverter and return a string. Like "MMMyyyy" How can I get this?
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var item = (DateTime)value;
if (item != null)
{
return item.ToString();
}
return null;
}
Please try below
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var item = (DateTime)value;
if (item != null)
{
return item.ToString("MMMyyyy");
}
return null;
}
Do you really need an IValueConverter here?
If you want this for a binding to display the databound DateTime with a specific format in WPF, you can use the StringFormat property of the Binding
Article about StringFormat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With