我有一个 WPF 应用程序,其中 WPF Toolkit DatePicker 控件绑定到 DateTime 变量,如下所示:
<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" />
我的代码:
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
}
}
但是当我运行它时,我收到错误消息“字符串未被识别为有效的日期时间。”
如果有任何错误,我该如何解决?谢谢。