なにが問題か:マークアップと比べて

XAML と比べて、分離コードを IronPython で記述すると、冗長になりがちです。そこで、XAML と同等の簡潔な表現ができるように、IronPython で拡張する方法を紹介します。

# apeCanvas.py ---------------------------------------- before ---
parent = Canvas(Width=180, Height=120)
child = Canvas(Width=50, Height=50,
Background=Brushes.Red)
parent.SetTop(child, 10)
parent.SetLeft(child, 10)
parent.Children.Add(child)

# catCanvas.py ---------------------------------------- after ---
parent = ExCanvas(None, Width=180, Height=120)
ExCanvas(parent, Width=50, Height=50,
background="Red", Top=10, Left=10)

分離コードを素の IronPython(--before--)で記述したものと比べると、拡張した IronPython(--after--)では、XAML と同等の簡潔な表現ができるのが分かります。