Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimePicker - Format #2622

Closed
pavelkocich opened this issue Aug 25, 2016 · 7 comments
Closed

DateTimePicker - Format #2622

pavelkocich opened this issue Aug 25, 2016 · 7 comments
Labels
Milestone

Comments

@pavelkocich
Copy link

It will be great if I can set DateTime format of string shown in DataPickerTextbox.

  • MahApps.Metro __v1.3.0-ALPHA189
  • Windows 10
  • Visual Studio 2015
  • .NET Framework 4.5
@stanleyipc
Copy link

Can you be more specific?

@michaelmairegger
Copy link
Contributor

Set Culture property. DateTimeFormat property is also not present on DatePicker

@pavelkocich
Copy link
Author

I can set Culture property of course, but it will be great to have more straightforward solution with property e.g. StringFormat, like Label control.

<Label ContentStringFormat="dd.MM.yyyy hh:mm" Content="{Binding MyDateTime}"/>

<controls:DateTimePicker StringFormat="dd.MM.yyyy hh:mm" SelectedDate="{Binding MyDateTime}" />

@anders9ustafsson
Copy link

Since this feature still is not implemented, are there any quick fixes that I could use instead? For example, I am using Culture sv-SE which gives me a date-time format yyyy-MM-dd HH:mm:ss. However, I don't want to display the seconds. Is there any way I can accomplish this using the Culture property only?

@punker76
Copy link
Member

@anders9ustafsson As a workaround you can override the time pattern with at a custom CultureInfo, cause the DateTimePicker uses this to format the text

var dateTimeFormat = string.Intern($"{formatInfo.ShortDatePattern} {formatInfo.LongTimePattern}");

e.g.

var ci = new CultureInfo("sv-SE");
ci.DateTimeFormat.LongTimePattern = ci.DateTimeFormat.ShortTimePattern;

then set this to the Culture property of the DateTimePicker.

/cc @xxMUROxx This should be easier to do in future release...

@anders9ustafsson
Copy link

@punker76 Thanks for the suggestion! I'll try it out.

@michaelmairegger
Copy link
Contributor

@punker76 I will provide a PR soon

michaelmairegger added a commit to michaelmairegger/MahApps.Metro that referenced this issue Apr 18, 2017
Add SelectedTimeFormat to TimePickerBase

Closes MahApps#2622
@punker76 punker76 added this to the 1.6.0 milestone May 15, 2017
@punker76 punker76 added the Bug label Feb 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

5 participants