Datepicker仅返回日期 [英] Datepicker returning only date

查看:110
本文介绍了Datepicker仅返回日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Datepicker控件获取日期并将其显示在WP7中的文本框中。我想要它只显示日期而不是时间。 Datepicker仅显示日期,但是当我想在TextBlock中显示日期和时间时。我使用数据绑定在Datepicker中设置日期:

Im using the Datepicker control to get a date and display it in a Textblock in WP7. I want it to only show the date and not the time. The Datepicker only shows the date, but when I want to show it in the TextBlock it shows both date and time. I use databinding to set the date in the Datepicker:

public class Task
{
    public DateTime Date { get; set; }
    public Task()
    {
        Date = DateTime.Now;
    }
}

XAML:

<toolkit:DatePicker Value="{Binding Mode=TwoWay, Path=Date}" FlowDirection="RightToLeft" />
<TextBlock x:Name="TxbTaskDate" Text="{Binding Date}" />

如何让TextBlock只显示日期而不是时间?

How do I get the TextBlock to only show the date and not time?

推荐答案

您应该添加一个StringFormat

You should add a StringFormat

<TextBlock x:Name="TxbTaskDate" 
           Text="{Binding Date, StringFormat='{}{0:dd.MM.yyyy}'}" />

这篇关于Datepicker仅返回日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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