如何从C#中的DatePicker(WPF)获取值? [英] How do I get value from DatePicker(WPF) in C#?

查看:823
本文介绍了如何从C#中的DatePicker(WPF)获取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序中有一个 DatePicker 类,但是如何从中获取实际值,例如19.12.2017?我试图应用在WinForms中从 DateTimePicker 获取值的方法,但是这种方法不起作用。

I have a DatePicker class in my program, but how do I get an actual value, such as 19.12.2017, from it? I've tried to apply the way that is used to get the value from DateTimePicker in WinForms but it didn't work.

推荐答案

您可以从DatePicker的SelectedDate属性中获取所选值。

You get the selected value from the SelectedDate property of the DatePicker.

<DatePicker x:Name="dp" />







DateTime? selectedDate = dp.SelectedDate;
if(selectedDate.HasValue)
{
    string formatted = selectedDate.Value.ToString("dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
}

这篇关于如何从C#中的DatePicker(WPF)获取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆