我有以下场景,我想在运行时更改StringFormat
a 。DataGridTextColumn
在我的DataGrid
我也DataGridTemplate
有一个Button
里面。当我按下时,Button
我想将StringFormat
小数点后两位更改为零小数位。我怎样才能做到这一点?我已经尝试过使用Styles
,Dynamic Resources
但到目前为止没有任何效果。此代码发生在我的AutogenerateColumns
-Event 中。DGC 是当前列。
DataTrigger t = new DataTrigger();
t.Binding = new Binding("Weight");
t.Value = 0;
Setter s = new Setter();
s.Property = DataGridCell.ContentStringFormatProperty;
s.Value = new Binding(null) { StringFormat = "N02" };
t.Setters.Add(s);
Sty.Triggers.Add(t);
DGC.CellStyle = Sty;