【问题标题】:textblock binding in windows metroWindows Metro中的文本块绑定
【发布时间】:2013-10-24 10:48:13
【问题描述】:

你好朋友,我想将我的 TextBlock 与“用户做了某事”之类的文本绑定在这里,用户是我想使用我在 wpf 中完成的文本块中的绑定来填充的可变部分。

<TextBlock Text="{Binding Artist.Fans.Count, StringFormat='Number of Fans: {0}'}"/>

但是当我尝试它时,windows metro 我得到这个字符串格式的错误没有定义所以我想知道有没有办法在不从属性发送整个自定义文本的情况下做到这一点..希望你得到我要问的任何东西感谢您的帮助或更好的想法。

【问题讨论】:

标签: c# xaml windows-8 microsoft-metro winrt-xaml


【解决方案1】:

很遗憾,WinRT 不支持 StringFormat。但你可以使用转换器:

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();
    }
}

【讨论】:

  • 我认为微软急于在没有正确实现的情况下启动 Windows 8
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多