マークアップと分離コード

マークアップと同様の結果が得られる、分離コードについて解説します。


GeometryGroup オブジェクトは、複数の Geometry オブジェクトで構成され、これらをプロパティー .Children で管理します。

# Path1.py
def shapes(self):
s = Path(
HorizontalAlignment=HorizontalAlignment.Center,
VerticalAlignment=VerticalAlignment.Center,
Stroke=Brushes.Blue,
StrokeThickness=2,
Fill=Brushes.Yellow,
Data=self.data(),
)
s.MouseUp += self.mouseUp
return s

def data(self):
g = GeometryGroup(
FillRule=FillRule.EvenOdd)

g.Children.Add(LineGeometry(
StartPoint=Point(10, 10),
EndPoint=Point(90, 10),
))
g.Children.Add(RectangleGeometry(
Rect=Rect(10, 45, 80, 30),
))
g.Children.Add(EllipseGeometry(
Center=Point(50, 60),
RadiusX=30,
RadiusY=30,
))
return g

def mouseUp(self, sender, e):
MessageBox.Show("%s%s"%
(sender, reduce(lambda a,e:
"%s\n%s"%(a,e), sender.Data.Children, "")))

ここでは、1つの GeometryGroup オブジェクトが、複数の Geometry オブジェクト(LineGeometry/RectangleGeometry/EllipseGeometry)で構成されます。そして、この GeometryGroup オブジェクトが、1つの Path を形成します。


Previous|5/5|Next