我想将数据贴纸选择日期绑定到一个对象,数据贴图显示的日期是dd / MM / yyyy,但是对象以mm / dd / yyyy格式重新显示日期。
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" />
我也试过这个:
<DatePicker Height="25" HorizontalAlignment="Left" Name="datePicker1" SelectedDate="{Binding Path=Data,StringFormat=0:dd/MM/yyyy}" VerticalAlignment="Top" Width="150" />
答案 0 :(得分:0)
试试这个:
DateTime dt = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day);
string[] formats = dt.GetDateTimeFormats();
return(formats[0]);
请查看此link以获取更多格式。