How would one achieve mixing bound values with constant text in a WPF bound control?
For example, say I have a form displaying orders, and I want a label that displa
If you're using 3.5 SP1, you can use the StringFormat property on the binding:
Otherwise, use a converter:
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.
[Edit : Change the Text property to Content]