You can use MultiBinding with a converter. First define an IMultiValueConverter that formats the first value using the format specified in the second:
public class FormatConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
Now bind both the ViewModel properties and the format to the same:
<MultiBinding Converter="{StaticResource formatter}"> <Binding Path="Price" /> <Binding Path="PriceFormat" /> </MultiBinding>
The nice part of this is that the logic of how Price should be formatted can live in the ViewModel and be testable. Otherwise, you could move this logic to the converter and pass any other properties they need.
Matt hamilton
source share