我希望下拉菜单在开始时显示年份而不是今天的日期。备注:标准 WPF DatePicker没有“DisplayMode”,如其他来源所示。
问问题
3553 次
3 回答
1
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "YYYY dd, mmmm - dddd";
或者:
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "YYYY mm, dddd - dddd";
如需更详细的说明,您可以单击此处。
于 2013-01-04T18:47:22.483 回答
1
非常感谢您的回答,但我找到了一个我更满意的解决方案(仅使用标准控件)
<DatePicker x:Name="_DatePicker" CalendarOpened="_DatePicker_CalendarOpened" />
private void _DatePicker_CalendarOpened(object sender, RoutedEventArgs e) {
// Finding the calendar that is child of stadart WPF DatePicker
DatePicker datepicker = (DatePicker)sender;
Popup popup = (Popup)datepicker.Template.FindName("PART_Popup", datepicker);
System.Windows.Controls.Calendar cal = (System.Windows.Controls.Calendar)popup.Child;
cal.DisplayMode = System.Windows.Controls.CalendarMode.Decade;
}
美好的一天,谢谢
于 2013-01-11T13:55:32.037 回答
0
如果您使用 WPF 工具包,那么
<toolkit:Calendar x:Name="yearCalender" DisplayModeChanged="yearCalender_DisplayModeChanged" DisplayMode="Year" />
C#代码:
private void yearCalender_DisplayModeChanged(System.Object sender, Microsoft.Windows.Controls.CalendarModeChangedEventArgs e)
{
yearCalender.DisplayMode = Microsoft.Windows.Controls.CalendarMode.Year;
}
于 2013-01-04T18:49:28.390 回答