看来,类似于Binding
在WinRT中,Binding
在 Windows Phone 通用应用程序中没有StringFormat
财产。解决此限制的一种可能方法是使用Converter
如中所解释的这篇博文 http://marcominerva.wordpress.com/2013/04/26/stringformat-converter-for-windows-store-apps/,
为了总结这篇文章,您可以创建一个IValueConverter
接受字符串格式作为参数的实现:
public sealed class StringFormatConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null)
return null;
if (parameter == null)
return value;
return string.Format((string)parameter, value);
}
public object ConvertBack(object value, Type targetType, object parameter,
string language)
{
throw new NotImplementedException();
}
}
在您的 XAML 中创建上述转换器的资源,然后您可以像这样使用它:
<TextBlock x:Name="countTextBlock"
Text="{Binding Count,
Converter={StaticResource StringFormatConverter},
ConverterParameter='{}{0:n}'}" />