Windows Phone 8.1 XAML StringFormat

我试图显示一些文本以及绑定数据,例如,我有代码:

 

我想在’速记’之前添加一些文本,从我读过的内容可以通过使用StringFormat作为Binding的属性来实现,这有点类似于:

  

然而,这似乎不起作用,这不再是8.1中做事的方式吗?

WinRT不支持StringFormat 。 但是,您可以通过创建自定义转换器轻松替换它:

 public class StringFormatConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { return string.Format(parameter as string, value); } public object ConvertBack(object value, Type targetType, object parameter, string language) { return null; } } 

然后在页面资源中声明它:

    

并在绑定中使用它:

  

就像@KooKiz指出的那样,目前不支持StringFormat ,但是你可以完成同样的效果,只需将你的行分解为内联运行而不需要像转换器一样;

      

希望这会有所帮助,欢呼。

我使用这种方法(由Microsoft编写): https : //msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.data.ivalueconverter

它很棒!