回复 5楼q406157290的帖子
- public override FrameworkElement GetCellEditingContent(DataGridRow row)
- {
- Control control;
- if (this.EditMode == DataGridDateTimeColumnEditMode.Custom)
- {
- control = new C1TextBoxBase();
- if (base.Binding != null)
- {
- Binding binding = base.CopyBinding(base.Binding, null);
- control.SetBinding(C1TextBoxBase.C1TextProperty, binding);
- }
- }
- else
- {
- C1DateTimePicker c1DateTimePicker = new C1DateTimePicker();
- switch (this.EditMode)
- {
- case DataGridDateTimeColumnEditMode.Date:
- c1DateTimePicker.EditMode = C1DateTimePickerEditMode.Date;
- break;
- case DataGridDateTimeColumnEditMode.Time:
- c1DateTimePicker.EditMode = C1DateTimePickerEditMode.Time;
- break;
- }
- c1DateTimePicker.DateFormat = this.DateFormat;
- c1DateTimePicker.TimeFormat = this.TimeFormat;
- c1DateTimePicker.CustomDateFormat = this.CustomDateFormat;
- c1DateTimePicker.CustomTimeFormat = this.CustomTimeFormat;
- c1DateTimePicker.HorizontalAlignment = base.HorizontalAlignment;
- c1DateTimePicker.AllowNull = base.AllowNull;
- c1DateTimePicker.MaxDate = this.MaxDate;
- c1DateTimePicker.MinDate = this.MinDate;
- if (this._firstDayOfWeekSet)
- {
- c1DateTimePicker.FirstDayOfWeek = this.FirstDayOfWeek;
- }
- c1DateTimePicker.Padding = new Thickness(0.0);
- c1DateTimePicker.CornerRadius = new CornerRadius(0.0);
- if (base.Binding != null)
- {
- Binding binding2 = base.CopyBinding(base.Binding, null);
- c1DateTimePicker.SetBinding(C1DateTimePicker.DateTimeProperty, binding2);
- }
- c1DateTimePicker.AddHandler(UIElement.KeyDownEvent,
- new KeyEventHandler(this.picker_KeyDown), true);
- control = c1DateTimePicker;
- }
- control.VerticalContentAlignment = base.VerticalAlignment;
- if (base.CellEditingContentStyle != null)
- {
- control.Style = base.CellEditingContentStyle;
- }
- return control;
- }
复制代码
DataGridDateTimeColumn实际上用的也是c1DateTimePicker控件的,只是该控件默认增减幅度为5分钟,
- C1DateTimePicker.TimeIncrementProperty = DependencyProperty.Register("TimeIncrement", typeof(TimeSpan), typeof(C1DateTimePicker), new PropertyMetadata(TimeSpan.FromMinutes(5.0)));
复制代码
而且在DataGridDateTimeColumn中C1DateTimePicker也是New出来的,且并未开放该控件属性或者该控件的增减幅度(TimeIncrement)属性,所以无法在XAML中配置;
程序员自当灵活使用控件,毕竟不会存在完美的控件,完美的代码,完美的程序员; |