Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top