私は WPF で非常に単純なゲームに取り組んでいます (wpf はゲーム用に設計されていないことは知っていますが、楽しみのためにやっています)。Enemy
から派生したクラスがありますCustomControl
。このコントロールのテンプレートを使用してコードを作成しました。コードは次のとおりです。
<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>
コントロールをパネルに配置すると、幅と高さが 20 単位に固定されます (上記のジオメトリ座標で定義されているように)。ただし、レイアウト プロセスで受け取った場所にシェイプを引き延ばしたいと考えています。Path
そのため、要素をに入れようとしましViewbox
たが、まだ幅と高さが 20 あります。
その問題を解決する簡単な方法はありますか?