I created a Pivot Project on Visual Studio 2013.
I created the following control:
<DatePicker Header="Data" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Width="341"/>
When I tap on it on my phone, it displays the date as M/D/Y. Is it possible to display it as D/M/Y?
Also, don't know if I should create another question, but how can I translate to pt-BR the day/month names shown within the control? As well as that "Choose a date".
The DatePicker format is using user's preferred language and region. This control will automatically look different, for my region it's day/month/year like you wish it to be. I've tried to force the control to use other language, but it seems to be taking it directly from phone settings. Some information you may find here at 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.
The other bad news you can find 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.
So in current API it may be hard to change the formatting.
The good news is for the CHOOSE DATE
text at the top - it's automatically localized, depending on user's language and region. So you don't have to worry about it if your app supports user's language. But I've not found way to change it to other text.
As for the text displayed inside the button before it's clicked, you can always use Button with DatePickerFlyout, a simple example with apropriate converter:
<Button Content="{Binding ElementName=chosenDate, Path=Date, Converter={StaticResource DateFormatConverter}}">
<Button.Flyout>
<DatePickerFlyout x:Name="chosenDate" />
</Button.Flyout>
</Button>
and the converter class:
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(); }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With