I've created a decorator which draws some custom graphics in OnRender method. The graphics depend on the position of the object containing the decorator. I set the decorator via Template property through Style. The problem is that the OnRender method of the decorator is called only once when the template is applied. So when I change the position of the object and call InvalidateVisual() on that object the decorator is not re-rendered.
I've managed to workaround this by setting the template of the object to null and then back to the same template like this:
if (myObject.Template != null)
{
ControlTemplate tmpTemplate = myObject.Template;
myObject.Template = null;
myObject.Template = tmpTemplate;
}
This does the trick but I'm sure this is not the way it should be done. What am I missing?