简体   繁体   中英

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?

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

datePicker1.ClearValue(DatePicker.SelectedDateProperty);

ClearValue() is looking for dependency properties.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM