Monday, January 17, 2011

WPF StringFormat Problems

If you're struggling to make StringFormat on a WPF binding work consider whether or not the data type you are binding to is matches the StringFormat you are using.

I've spent too long today trying to make StringFormat work on a DataGrid column bound to a DataTable column which I thought was a double. It didn't seem to matter what I used as the StringFormat, the data would always display the same. I'd forgotten to specify the DataColumn DataType and so when I assigned values to the column, they were stored a string and didn't respond to StringFormats that expected double values.