silverlight Calendar 选择月份的时候能不能不进选择日期的
这个点击月份的时候就自动进去选择几号的了
能不能到选择月份就终止了?
[解决办法]
楼主可以修改Silverlight Toolkit代码实现,创建一个新的依赖属性实现。
可以参考以下代码可以实现Calendar只选月份:
public CalendarMode CalendarMode{ get { return (CalendarMode)GetValue(CalendarModeProperty); } set { SetValue(CalendarModeProperty, value); }}public static readonly DependencyProperty CalendarModeProperty = DependencyProperty.Register( "CalendarMode", typeof(CalendarMode), typeof(DatePicker), new PropertyMetadata(OnCalendarModeChanged)); private static void OnCalendarModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e){ DatePicker dp = d as DatePicker; // get the new value into a calendar mode variable. CalendarMode cm = (CalendarMode)e.NewValue; if (dp != null) { dp._calendar.DisplayMode = cm; }}private void InitializeCalendar(){ _calendar = new Calendar(); _calendar.DayButtonMouseUp += new MouseButtonEventHandler(Calendar_DayButtonMouseUp); _calendar.DisplayDateChanged += new EventHandler<CalendarDateChangedEventArgs> (Calendar_DisplayDateChanged); _calendar.SelectedDatesChanged += new EventHandler<SelectionChangedEventArgs> (Calendar_SelectedDatesChanged); _calendar.MouseLeftButtonDown += new MouseButtonEventHandler (Calendar_MouseLeftButtonDown); _calendar.KeyDown += new KeyEventHandler(Calendar_KeyDown); _calendar.SelectionMode = CalendarSelectionMode.SingleDate; _calendar.SizeChanged += new SizeChangedEventHandler(Calendar_SizeChanged); _calendar.IsTabStop = true; #region Juan Mejia - Modification _calendar.DisplayMode = this.CalendarMode; _calendar.DisplayModeChanged += new EventHandler<CalendarModeChangedEventArgs> (Calendar_DisplayModeChanged); #endregion}private void Calendar_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e){ if (this.CalendarMode == CalendarMode.Year) { if (_calendar.DisplayMode == CalendarMode.Month) { _calendar.DisplayMode = CalendarMode.Year; if (_popUp.IsOpen) { this.SelectedDate = _calendar.SelectedMonth; this._popUp.IsOpen = false; } } }}<sdk:DatePicker Name="datepicker1" Height="23" Width="150" SelectedDateFormat="MonthYear" CalendarMode="Year" />