WPF XAML中的日期字符串格式 [英] WPF Date String Format in XAML

查看:1181
本文介绍了WPF XAML中的日期字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图格式字符串日期后由DatePicker选择。我得到的格式是9/5/2013 12:00:00 AM,我想得到的是9/5/2013​​。有人能告诉我我在字符串格式上做错了什么?

I am trying to format string after a date has been selected by the DatePicker. The Format that I am getting is "9/5/2013 12:00:00 AM" and what I am trying to get is "9/5/2013". Can someone tell me what I am doing wrong with the string format?

<DataGridTemplateColumn Header="Start">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Start, StringFormat=d}" FontFamily="Verdana" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <DatePicker SelectedDate="{Binding Start}" FontFamily="Verdana"  >
                <DatePicker.CalendarStyle>
                    <Style TargetType="Calendar">
                          <Setter Property="DisplayMode" Value="Month"/>
                    </Style>
                </DatePicker.CalendarStyle>
            </DatePicker>
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>


推荐答案

请尝试以下操作:

<TextBlock Text="{Binding Start, StringFormat=d}" />

这需要.NET 3.5 SP1或更高版本。

This requires .NET 3.5 SP1 or above.

Btw .: StringFormat区分大小写。 d是短日期格式说明符,而D是长日期格式说明符

Btw.: StringFormat is case sensitive. "d" is the short date format specifier while "D" is the long date format specifier.

这篇关于WPF XAML中的日期字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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