I’m using ellipses and other shapes as onscreen markers, I would like others to be able to change these visuals using templates. However, as shape doesn’t support templating I’m forced to create a basic UserControl, which defaults to show an ellipse, and then use that instead of the basic shape.
Has anyone got a neater solution? I’m a little concerned if I create 1000’s of these onscreen that performance/memory will be a bit of an overhead.
UserControlderives fromContentControl. It doesn’t sounds as though you need content (the ability to host additional controls inside your shape), so I’d keep going up the hierarchy…Here’s a breakdown of the ancestry:
Controldefines theTemplateproperty, so I think the lightest means of achieving what you want is to useControl:…and use a
Styleto set the template and any triggers/etc that you need.If however you do need to host a child element inside your shape, you should use
ContentControlthus:If you find that this approach is too heavy-weight at runtime, then you might consider using Shape.
Shapedoes not inherit fromControl, but rather directly fromFrameworkElement. It is not templateable. It’s an abstract class, of which you’d need to create your own custom subclass that knows how to describe its own presentation via theDefiningGeometryproperty. This might be more complex than defining a style on aControl, but if you need the extra performance then you may have to go this route.EDIT You might like to check out DrawingVisual as well. From MSDN:
It also is not templateable, but if you need raw performance then it’s worth a look.