If you're using 3.5 SP1, you can use the StringFormat
property on the binding:
<Label Text="{Binding Order.ID, StringFormat=Order ID \{0\}}"/>
Otherwise, use a converter:
<local:StringFormatConverter x:Key="StringFormatter" StringFormat="Order ID {0}" />
<Label Text="{Binding Order.ID, Converter=StringFormatter}"/>
With StringFormatConverter
being an IValueConverter
:
[ValueConversion(typeof(object), typeof(string))]
public class StringFormatConverter : IValueConverter
{
public string StringFormat { get; set; }
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture) {
if (string.IsNullOrEmpty(StringFormat)) return "";
return string.Format(StringFormat, value);
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
That'll do the trick.