您好我想在文本框中显示datetimepicker中的所选日期。我尝试了以下但是得到了值的错误:DatePicker不包含'Value'的定义,接受类型''的第一个参数无法找到..
private void datePicker_ValueChanged(object sender, EventArgs e)
{
DateTime date = this.datePicker.Value;
this.txtExpire.Text = date.ToString("dd-mm-yyyy");
}
答案 0 :(得分:4)
使用DateTime? date = this.datePicker.SelectedDate
代替值。
答案 1 :(得分:1)
DateTime date = this.datePicker.SelectedDate;
答案 2 :(得分:0)
使用SelectedDate属性而不是Value ...
http://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker.aspx
答案 3 :(得分:0)
如果您只需要将文本块绑定到DatePicker,请使用xaml绑定:
<DatePicker x:Name="DatePicker" />
<TextBlock Text="{Binding ElementName=DatePicker, Path=SelectedDate, StringFormat=d}"/>