loop
loop

Reputation: 9242

textblock binding in windows metro

hello friends i want to bind my TextBlock with some text like "user done something " here user is variable part that i wanted to fill using binding in textblock i have done in wpf like this.

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

but when i tried it windows metro i am getting this error of string format is not defined so i wanted to know is there any way to do it without sending whole custom text from property..hope you got what i am asking any help or better idea is appreciated.

Upvotes: 0

Views: 405

Answers (1)

Oliver Weichhold
Oliver Weichhold

Reputation: 10306

StringFormat is unfortunately not support in in WinRT. But you could use a converter instead:

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

Upvotes: 1

Related Questions