gpt4 book ai didi

date - DatePicker 上显示的格式日期

转载 作者:行者123 更新时间:2023-12-04 21:13:03 24 4
gpt4 key购买 nike

我在 Visual Studio 2013 上创建了一个 Pivot 项目。

我创建了以下控件:

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

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

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

enter image description here

最佳答案

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顶部的文本 - 它会自动本地化,具体取决于用户的语言和地区。因此,如果您的应用支持用户的语言,您就不必担心。但我还没有找到将其更改为其他文本的方法。

至于在单击按钮之前显示在按钮内的文本,您始终可以将 Button 与 DatePickerFlyout 一起使用,这是一个带有适当转换器的简单示例:

<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, Type targetType, object parameter, string language) { throw new NotImplementedException(); }
}

关于date - DatePicker 上显示的格式日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30446872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com