wpf 使用 XAML 将 DatePicker 设置为今天

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15794687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:27:21  来源:igfitidea点击:

Set DatePicker to Today using XAML

wpfxamlbindingdatepicker

提问by Dom

I have the following DatePickercontrol in my project:

我的项目中有以下DatePicker控件:

<DatePicker x:Name="startDate" SelectedDate="2013-04-03"></DatePicker>

QUESTION:
Is it possible to set the DatePicker.SelectedDateusing only XAML?

问题:
是否可以设置DatePicker.SelectedDate仅使用 XAML?

I know this can be achieved using code-behind.

我知道这可以使用代码隐藏来实现。

回答by Kevin DiTraglia

Try this...

尝试这个...

Add this to xaml refs:

将此添加到 xaml 引用:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

Then write this:

然后这样写:

<DatePicker SelectedDate="{x:Static sys:DateTime.Now}"/>