IEditorStrategy and DateTimePicker

18 views
Skip to first unread message

Corey Cole

unread,
Aug 9, 2012, 11:14:14 PM8/9/12
to magellan...@googlegroups.com
I'm trying to adapt the example IEditorStrategy for use with a DateTime value.

On my first pass through, I was able to use the default WPF DatePickerTextBox primitive.  It seems to work, as a blank value in the text box gets highlighted as invalid.
If I replace the WPF primitive with Xceed.Wpf.Toolkit.DateTimePicker, then I don't get the correct control.  It's still a text box.

public class DateTextBoxEditorStrategy : IEditorStrategy
    {
        public object CreateEditor(FieldContext context)
        {
            var isDate = context.PropertyDescriptor.PropertyType == typeof(DateTime);

            if (!isDate)
            {
                return null;
            }
            var picker = new Xceed.Wpf.Toolkit.DateTimePicker();
            picker.Format = DateTimeFormat.ShortDate;
            BindingOperations.SetBinding(picker, TextBox.TextProperty, context.Binding);
            return picker;
        }
    }

Is this the correct way to go about this?  Or is there a better way of handling dates? 




Reply all
Reply to author
Forward
0 new messages