【发布时间】:2013-07-02 05:42:57
【问题描述】:
我只想返回日期(而不是时间),但我已经尝试了所有方法,它总是返回
7/23/2013 12:00:00 AM
但我只想要
7/23/2013
这是我的代码,需要在纯 XAML 中完成。
<DatePicker SelectedDate="{Binding myDateProperty}" Height="30" HorizontalAlignment="Left" Margin="0,1,5,1" Name="ObsoleteDate" VerticalAlignment="Top" Width="110">
<DatePicker.Resources>
<Style TargetType="{x:Type DatePickerTextBox}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<TextBox x:Name="PART_TextBox" Text="{Binding Path=SelectedDate, RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}, StringFormat={}{0:dd/MM/yyyy}}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DatePicker.Resources>
</DatePicker>
【问题讨论】:
-
您只需要日期吗?在用户界面上还是在您的视图模型中?你试过 SelectedDateFormat 了吗?
-
在视图模型中。试过 SelectedDateFormat="Short" 但结果相同。
-
"12:00:00" 是默认值,如果您不关心时间,可以使用 Date 部分:msdn.microsoft.com/en-us/library/system.datetime.date.aspx
-
你能显示你的视图模型代码吗?你总是可以使用转换器来得到你想要的
标签: wpf xaml datepicker