Ok! I found it!
The problem was the way I was adding the setter to the ControlTemplate, so instead of:
cellStyle.Setters.Add(new Setter() { Property = CellValuePresenter.TemplateProperty, Value = ((object)new CellValuePresenter() { Template = ct }) });
It should be something like this:
cellStyle.Setters.Add(new Setter(CellValuePresenter.TemplateProperty, ct));
And then it works!
I know it is not the best way to do it but that's how I was asked to do it.