I’ve got a WPF DataGrid and wish to apply a currency format to several of the columns. I can do this on a per-column basis using Binding={Binding FieldName, StringFormat={}{0:C}, but I’d prefer to define the currency format once – presumably in a <Style> resource – and just apply that resource to each column that needs formatting.
Problem is, I’ve no idea how to set a Binding’s StringFormat property from within a style. Is it possible to set that or a similar property in a <Style>, or am I barking up the wrong tree with this approach?
Update: I’ve successfully applied a style to the cells in my DataGridTextColumn, and setting the ContentStringFormat property of the cell seems like it’d be the way to go… but whatever value I put in there seems to get ignored.
You could create a Template for a DataGrid cell, and use the
{TemplateBinding ContentPresenter.Content}value for the converter parameter.I haven’t tested this code, but something like: