I have the following Scenario where I want to change the StringFormat of a DataGridTextColumn on runtime. On my DataGrid I have also a DataGridTemplate with a Button inside. When I press the Button I want to change the StringFormat from two decimal places to zero decimal places. How can I do that? I have already tried working with Styles and Dynamic Resources but nothing is working so far. This Code happens in my AutogenerateColumns-Event. DGC is the current column.
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;