I want to create a custom Shape
control, that paints different shapes like Polygon
, Ellipse
, Rectangle
, etc, depending on some custom properties.
I was able to create a custom template control ColorShape
like this:
<Style TargetType="local:CustomShape">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CustomShape">
<ContentControl x:Name="shapeParent">
</ContentControl>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And then, override the OnTemplateChanged
method, and insert a corresponding Shape
control inside the shapeParent
ContentControl
But what I'd like is to actually extend the Shape
, so I can treat all the shapes, framewok and custom, in the same way.
In WPF we were able to extend the Shape
and override the property DefiningGeometry
.
In UWP it doesn´t exist any DefiningGeometry
property to override.
How is it possible to create a custom Shape
control and define the corresponding Geometry?
The only way I found to create custom shapes in UWP is to extend the
Path
class and set itsData
property.Updating the
Data
property to account for changes in other dependency properties (likeWidth
) must not be done in layouting relevant sections, like theLayoutUpdated
event or theArrangeOverride
method.Setting
Data
leads to another layout run, so setting it in anything that is called during that would lead to an exception:The way I use is to register handler for property changed events and update
Data
in them.I have written a blog post that explains it in a bit more detail.
This is the example I used: