I am working on a very simple game in WPF (I know that wpf is not designed for games, but I do it for fun). I have an Enemy
class which derives from CustomControl
. I wrote a piece of code with the template for this control.
here is the code:
<ControlTemplate TargetType="{x:Type elements:Enemy}">
<Grid Width="{TemplateBinding ElementWidth}" Height=" {TemplateBinding ElementHeight}">
<Path Fill="LightGoldenrodYellow" >
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="20,20" IsClosed="True">
<PathFigure.Segments>
<LineSegment Point="18, 5"/>
<ArcSegment Point="2,5" SweepDirection="Counterclockwise" RotationAngle="90" Size="3,5"/>
<LineSegment Point="0,20"/>
<LineSegment Point="5,17"/>
<LineSegment Point="10,20"/>
<LineSegment Point="15,17"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<Path Fill="{TemplateBinding Background}"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="{TemplateBinding BorderThickness}">
<Path.Data>
<GeometryGroup FillRule="EvenOdd">
<PathGeometry>
<PathFigure StartPoint="20,20" IsClosed="True">
<PathFigure.Segments>
<LineSegment Point="18, 5"/>
<ArcSegment Point="2,5" SweepDirection="Counterclockwise" RotationAngle="90" Size="3,5"/>
<LineSegment Point="0,20"/>
<LineSegment Point="5,17"/>
<LineSegment Point="10,20"/>
<LineSegment Point="15,17"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry>
<EllipseGeometry Center="6,6" RadiusX="3" RadiusY="3"/>
<EllipseGeometry Center="14,6" RadiusX="3" RadiusY="3"/>
<EllipseGeometry Center="6,6" RadiusX="1.5" RadiusY="1.5"/>
<EllipseGeometry Center="14,6" RadiusX="1.5" RadiusY="1.5"/>
<RectangleGeometry Rect="5,10,10,5" RadiusX="0" RadiusY="0"/>
<RectangleGeometry Rect="6,10,2.5,2"/>
<RectangleGeometry Rect="9,13,2.5,2"/>
<RectangleGeometry Rect="12,10,2.5,2"/>
</GeometryGroup>
</Path.Data>
</Path>
</Grid>
</ControlTemplate>
And now I have a problem, because if I placed my control on a panel, it would have fixed width and height to 20 units (as defined in geometry coordinates above).
However, I want my shape to be streatched to the place that it recieves in the layout process. So I have tried to put my Path
element into Viewbox
, but it still has 20 width and height.
Is there any simple way that solves that problem?