What would be the most efficient way to set customized formatting of the column in DataGrid? I can’t use the following StringFormat, as my sophisticated formatting also depends on some other property of this ViewModel. (e.g Price formatting has some complicated formatting logic based on different markets.)
Binding ="{Binding Price, StringFormat='{}{0:#,##0.0##}'}"
You could use a MultiBinding with a converter. First define an IMultiValueConverter that formats the first value using the format specified in the second:
Now bind both your ViewModel property and the format to the same thing:
The nice part about this is that the logic for how Price should be formatted can live in the ViewModel and be testable. Otherwise you could move that logic into the converter and pass in any other properties that it needed.