DateTimePicker从一年开始 [英] DateTimePicker start on year

查看:154
本文介绍了DateTimePicker从一年开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有几个关于格式化C#DateTimePickers的QAs,但是没有一个似乎解决了这个方面:

There are several QAs here about formatting C# DateTimePickers, but none seem to address this aspect:

默认行为是当用户单击他开始的DateTimePicker下拉列表一个月的视图,一个滚动条在一个页面上一个月。

The default behavior is when the user clicks the DateTimePicker dropdown he starts at the one-month view, with a scroll bar on top to page through one month at a time.

从用户界面,您可以移动到一年级,但我的操作员不是本地的或直观的控制使用。我要求用户输入跨越10年的数据(某些产品的生产日期)。我想从年级开始,使得在任意一个地方附近开始更快/更容易开始。

From the UI, you can move up to year level, but my operators are not local or intuitive with control use. I'm requesting that the user enter data that spans 10 years (date of manufacture for some product). I want to start at the year level to make it faster/easier to start near the right arbitrary place.

我可以使日历下拉菜单在年级自动开始,然后钻取

Can I make the calendar pulldown automatically start at year level and drill down?

谢谢。

推荐答案

如果您使用WPF我假定你是指DatePicker控件。

If you are using WPF then I presume you are referring to the DatePicker control.

在你的XAML中:

<DatePicker CalendarOpened="DatePicker_CalendarOpened" />

然后在

using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

private void DatePicker_CalendarOpened(object sender, RoutedEventArgs e)
{
    DatePicker datepicker = (DatePicker)sender;
    Popup popup = (Popup)datepicker.Template.FindName("PART_Popup", datepicker);
    Calendar cal = (Calendar)popup.Child;
    cal.DisplayMode = CalendarMode.Year;
}

这篇关于DateTimePicker从一年开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆