I'm trying to place a simple string
inside a Rectangle
. I'm using GeometryGroup
for that purpose, and here is my code:
protected override Geometry DefiningGeometry
{
get
{
var geoGroup = new GeometryGroup();
var text = new FormattedText("Hello", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Times New-Roman"), 150, ShapeContainer.Color);
var geometry = text.BuildGeometry(ShapeContainer.Location);
geoGroup.Children.Add(new RectangleGeometry(new Rect(100, 100, 200, 100)));
geoGroup.Children.Add(geometry);
return geoGroup;
}
}
For some reason, the text I'm getting is doubled (see attached image).
Can't I convert Label
-style text into Geometry
for printing it alongside a Rectangle
?