加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

DatePicker上显示的格式日期

发布时间:2020-12-14 02:50:59 所属栏目:Windows 来源:网络整理
导读:我在Visual Studio 2013上创建了一个Pivot项目. 我创建了以下控件: DatePicker Header="Data" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0" Width="341"/ 当我在手机上点击它时,它会将日期显示为M / D / Y.是否可以将其显示为D /
我在Visual Studio 2013上创建了一个Pivot项目.

我创建了以下控件:

<DatePicker Header="Data" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0" Width="341"/>

当我在手机上点击它时,它会将日期显示为M / D / Y.是否可以将其显示为D / M / Y?

此外,不知道我是否应该创建另一个问题,但是如何将pt-BR转换为控件中显示的日/月名称?以及“选择日期”.

解决方法

DatePicker格式使用用户的首选语言和区域.此控件将自动显示不同,对于我的区域,它是您希望的日/月/年.我试图强制控件使用其他语言,但它似乎直接从手机设置.您可以在 MSDN找到一些信息:

If you need to allow users to choose a date or select a time,use the standard date and time picker controls. These will automatically use the date and time formats for the user’s preferred language and region.

你可以找到其他坏消息here at MSDN about formating that particular control:

Note This section applies to Windows Store apps using C++,C#,or Visual Basic. Formatting is ignored in Windows Phone Store apps.

因此,在当前的API中,可能很难更改格式.

好消息是顶部的CHOOSE DATE文本 – 它会自动本地化,具体取决于用户的语言和区域.因此,如果您的应用支持用户的语言,则无需担心.但我没有办法将其改为其他文字.

对于单击按钮之前显示的文本,您可以随时使用带有DatePickerFlyout的Button,这是一个带有适当转换器的简单示例:

<Button Content="{Binding ElementName=chosenDate,Path=Date,Converter={StaticResource DateFormatConverter}}">
    <Button.Flyout>
        <DatePickerFlyout x:Name="chosenDate" />
    </Button.Flyout>
</Button>

和转换器类:

public class DateFormatConverter : IValueConverter
{
    public object Convert(object value,Type targetType,object parameter,string language)
    {
        DateTimeOffset chosen = (DateTimeOffset)value;
        return string.Format("{0}/{1}/{2}",chosen.Day,chosen.Month,chosen.Year);
        // or use chosen.ToString() with format provider
    }

    public object ConvertBack(object value,string language) { throw new NotImplementedException(); }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读