What you ask for is not so difficult to achive: Xceed PropertyGrid
is high customizable and a property editor can be customized by using the ITypeEditor interface and the Editor attribute.
First of all we need to define a custom editor control:
public class DateTimePickerEditor : DateTimePicker, ITypeEditor
{
public DateTimePickerEditor()
{
Format = DateTimeFormat.Custom;
FormatString = "dd.MM.yyyy";
TimePickerVisibility = System.Windows.Visibility.Collapsed;
ShowButtonSpinner = false;
AutoCloseCalendar = true;
}
public FrameworkElement ResolveEditor(PropertyItem propertyItem)
{
Binding binding = new Binding("Value");
binding.Source = propertyItem;
binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
BindingOperations.SetBinding(this, ValueProperty, binding);
return this;
}
}
All the stuff in the constructor are made for obtaining a specific behavior (i.e. no time controls, a specific date format and so on).
Now we need to set the DateTimePickerEditor
as the default editor for the object property (that in our sample is called "Date"):
[Category("General")]
[DisplayName("Date")]
[PropertyOrder(2)]
[Editor(typeof(DateTimePickerEditor), typeof(DateTimePicker))]
public Nullable<DateTime> Date
I hope it helps.