문제

I found some usefull question but they didn't helped me. I'm developing Windows Phone 8 app and I want to show only dd.MM on TextBlock (DateTime binded) if culture is Turkish. If culture is en than display MM.dd

 Text="{Binding MyProperty.CreateDate, StringFormat=\{0:dd.MM\}}"

Above code runs true in Turkish culture. But in English it's meaningless. Actually problem is not with the English or turkish. I just want to show Day and Month formatted in current culture.

도움이 되었습니까?

해결책

If you want to specify your own format, you can create different format strings in your localization resource files and bind to StringFormat

Text="{Binding MyProperty.CreateDate, StringFormat={StaticResource shorDateFormatString}}"

Alternatively, set the date text in the codebehind, with some custom logic to see whether the month or the day comes first in the local convention

string shortDatePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern
if(shortDatePattern.indexOf("dd") < shortDatePattern.indexOf("MM"))
  dateLabel.Text = MyProperty.CreateDate.toString("dd.MM")
else
  dateLabel.Text = MyProperty.CreateDate.toString("dd.MM")

As suggested in this response

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top