我不知道如何将格式参数添加到以下 DataGrid 列。我需要用两位小数显示数字。
我有一个silverlight DataGrid,我正在动态添加列。我创建列并应用动态绑定(我知道它有效)
public static DataGridTextColumn CreateFloatColumn(int index, string fieldName, string header, string description)
{
DataGridTextColumn column = new DataGridTextColumn();
column.Header = header;
column.HeaderStyle = BuildColumnHeaderStyle(description);
Binding newBinding = new Binding("floatValuesList[" + index + "]");
column.Binding = newBinding;
column.CellStyle = BuildCellStyle(fieldName, description);
return column;
}
现在我还需要格式化值。在这种情况下,显示的是一个浮点值。如何将格式应用于绑定?在这一点上,我想要的只是要显示的数字和两个小数点,但我希望它有点灵活,让我显示可变数量的小数点。
(编辑:删除字符串 IValueConverter 概念以保持问题更清晰)