Wpf XAML日期选择器仅返回日期而不返回时间

Wpf XAML日期选择器仅返回日期而不返回时间,wpf,xaml,datepicker,Wpf,Xaml,Datepicker,我只想返回日期(不是时间),但我尝试了所有方法,结果总是返回 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=

我只想返回日期(不是时间),但我尝试了所有方法,结果总是返回

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>


使用
StringFormat=d
代替
StringFormat={}{0:dd/MM/yyyyy}
我使用了下面的代码,它对我有效。(
obsoledate
是您的
日期选择器的名称



为我工作过

你想要哪一天?在ui上还是在viewmodel中?是否尝试了viewmodel中的SelectedDateFormat。尝试了SelectedDateFormat=“Short”但结果相同。“12:00:00”是默认值,如果您不在乎时间,可以使用日期部分:请显示您的viewmodel代码。你总是可以使用转换器来得到你想要的
ObsoleteDate.SelectedDate.Value.Date.ToShortDateString()
<TextBox Background="#fff" x:Name="PART_TextBox" Text="{Binding Path=SelectedDate, 
RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}, StringFormat=d}" />