我玩新
Windows Store通用应用程序模板,可用于Windows 8.1和Windows Phone 8.1,并想知道如何格式化字符串在XAML代码.
我试过了(XAML):
<TextBlock Text="{Binding TestItem.CurrentDate,StringFormat={}{0:MM/dd/yyyy}}" />
问题是StringFormat在Windows.UI.Xaml.Controls.TextBox中不可用.
Microsoft已经创建了一个sample project,这是关于格式化日期.但是使用的方法是基于(丑))代码.
所以,这是我的问题:
>为什么StringFormat在Windows Store Universal Apps中不可用?
>如何使用XAML代码格式化字符串?
public class DateConverter : IValueConverter { public object Convert(object value,Type targettype,object parameter,string language) { if (value == null) return null; if (!(value is DateTime)) return null; var dateTime = (DateTime)value; var dateTimeFormatter = new DateTimeFormatter(YearFormat.Full,MonthFormat.Full,DayFormat.Default,DayOfWeekFormat.None,HourFormat.None,MinuteFormat.None,SecondFormat.None,new[] { "de-DE" },"DE",CalendarIdentifiers.Gregorian,ClockIdentifiers.TwentyFourHour); return dateTimeFormatter.Format(dateTime); } public object ConvertBack(object value,string language) { throw new NotImplementedException(); } }
谢谢MikaelDúiBolinder和Martin Suchan的建议/回答.