pencilslate
pencilslate

Reputation: 13068

How to clear datepicker control in silverlight?

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?

Upvotes: 1

Views: 4721

Answers (2)

Kestutis
Kestutis

Reputation: 125

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;
}

Upvotes: 1

user179700
user179700

Reputation: 522

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

datePicker1.ClearValue(DatePicker.SelectedDateProperty);

ClearValue() is looking for dependency properties.

Upvotes: 5

Related Questions