Click here to Skip to main content
15,886,518 members

I got this error string was not recognized as a valid datetime when I validate WPF DatePicker control

Revision 1
I have a WPF application, with a WPF Toolkit DatePicker control bound to a DateTime variable as following:

<myToolkit:DatePicker Grid.Row="4" Grid.Column="4" x:Name="clndrHiredate" HorizontalAlignment="Left" Height="20" Width="150" VerticalAlignment="Top" FontFamily="Tahoma" FontWeight="Light" FlowDirection="RightToLeft" SelectedDate="{Binding bindingDate,StringFormat='{}{0:MM/dd/yyyy}', Mode=TwoWay}" />

<Button Grid.Row="8" Grid.Column="4" Style="{StaticResource GlassButton}" x:Name="btnRead" Height="29" Content="Read" FontSize="14" Foreground="White" HorizontalContentAlignment="Center" FontFamily="Arial" FontWeight="Bold" Background="#FF47594E" Margin="64,13,31,196" Width="65" />
And my code :

private DateTime bindingDate = DateTime.Now;

private void btnRead_Click(object sender, RoutedEventArgs e)
{
      if (string.IsNullOrEmpty(clndrHiredate.SelectedDate.ToString()))
      {
          errorText += MessageBox.show("Wrong");
          state = true;
          lblHireDate.Visibility = Visibility.Visible;
      }
      else
      {
          // complete 
      }
}
but when I run this , I got error message "string was not recognized as a valid datetime."

If there is any error, How do I fix this? 

Thanks.
Posted 10-Nov-12 10:12am by Doudy_2020.
Tags: , ,