how to use ivalueconverter to convert datetime to specified string format

Posted by Raj_Chennai under WPF on 10/29/2013 | Points: 10 | Views : 2168 | Status : [Member] | Replies : 5
how to use ivalueconverter to convert datetime to specified string format mentioned by the user either by binding in xaml or from codebehind

raj


Responses

Posted by: Bandi on: 10/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
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;
}



Reference:
http://stackoverflow.com/questions/11666028/how-to-set-datetime-format-in-ivalueconverter-and-return-string-value
http://stackoverflow.com/questions/16806857/datetime-format-in-wpf
http://dotnet.dzone.com/news/formatting-your-wpf-data-%E2%80%93


Click on "Mark as Answer "

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj_Chennai on: 11/6/2013 [Member] Starter | Points: 25

Up
0
Down
the format should be mentioned by the user only at runtime

raj

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
May be try this........
string strFormat = txtFormat.Text;
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){
var item = (DateTime)value;
if (item != null and strFormat != null )
{
return item.ToString(strFormat);
}
return null;
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Net on: 11/7/2013 [Member] Starter | Points: 25

Up
0
Down

hi rajkumar,
Refer :
http://www.wpf-tutorial.com/data-binding/value-conversion-with-ivalueconverter

Rajesh.
Software Engineer





If it helps/directs you towards the solution,Mark This Response as Answer link
--
Rajesh

Raj_Chennai, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response