c# - Delete input if date is invalid : XAML datepicker -


i working datepicker control in silverlight. want delete input if date invalid.

i have tried following code :

xaml:

<sdk:datepicker height="23" x:name="datepicker1" width="179"                  datevalidationerror="datepicker1_datevalidationerror"  /> 

c#:

private void datepicker1_datevalidationerror(object sender, datepickerdatevalidationerroreventargs e)     {         try         {              if (datepicker1.selecteddate != null && (regex.ismatch(datepicker1.selecteddate.tostring(), @"^([1-9]|0[1-9]|1[0-2])[- / .]([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])[- / .](1[9][0-9][0-9]|2[0][0-9][0-9])$")))             {               //working fine             }                 else             {                 messagebox.show("please enter valid date");                 datepicker myelement = ((frameworkelement)system.windows.application.current.rootvisual).findname("datepicker1") datepicker;    // search control named "datepicker1"                  myelement.text = string.empty;              }          }         catch          {           }  } 

but myelement returns null , can not delete invalid input.

here's code used similar thing:

code behind:

private void datepicker_datevalidationerror(object sender, datepickerdatevalidationerroreventargs e)         {              var mydatepicker = sender datepicker;              datepickertextbox datebox = mydatepicker.getvisualdescendants().oftype<datepickertextbox>().firstordefault();             if (datebox != null)             {                 datebox.text = string.empty;             }             // clear selecteddate property too, otherwise you'll left last valid 1             mydatepicker.selecteddate = null;         } 

xaml:

<sdk:datepicker datevalidationerror="datepicker_datevalidationerror"/> 

i have number of pickers on same form, , sharing datevalidationerror handler, hence not finding picker name.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -