Bind datapicker to an object in dd/MM/yyyy format
I want to bind datapicker se开发者_如何学Pythonlected date to an object, the date presented by the datapicker is dd/MM/yyyy but the object recievs date in mm/dd/yyyy format.
Ob ob = new Ob();
public Window1()
{
InitializeComponent();
this.DataContext=ob;
}
public class Ob
{
public string Data { get; set; }
}
<DatePicker Height="25" HorizontalAlignment="Left" Name="datePicker1" SelectedDate="{Binding Path=Data}" VerticalAlignment="Top" Width="150" />
I also tried this:
<DatePicker Height="25" HorizontalAlignment="Left" Name="datePicker1" SelectedDate="{Binding Path=Data,StringFormat=0:dd/MM/yyyy}" VerticalAlignment="Top" Width="150" />
Try this out :
DateTime dt = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day);
string[] formats = dt.GetDateTimeFormats();
return(formats[0]);
Have look on this link for more formats.
精彩评论