views:

554

answers:

2

I am using the standard datepicker control from silverlight. If i happen to type junk text into it and try to clear the data by setting the Text property to empty, it wouldn't clear the data.

There is a method called ClearValue but not sure what to give as input parameter.

What could i be missing here?

+2  A: 

Well, I can give you the format for ClearValue().

datePicker1.ClearValue(DatePicker.SelectedDateProperty);

ClearValue() is looking for dependency properties.

+1  A: 

ClearValue didn't work for me so I had to find other solution to clear DatePicker. I used VisualTreeExtensions from Silverlight toolkit to select DatePickerTextBox which is rendered inside DatePicker control and reset its Text property. This way reset works even when user enters incorrect data into control.

DatePickerTextBox dateBox = validation.GetVisualDescendants().OfType<DatePickerTextBox>().FirstOrDefault();
if (dateBox != null)
{
    dateBox.Text = String.Empty;
}
Kestutis