myBlog

IronPython, Silverlight, WPF, XAML, HTML5, ...

IronPythonで、XAMLから、ドックパネル( DockPanel )を表示

2011-07-06 17:11:52 | IronPython
今回は、シンプルなプログラムです。
IronPythonで、XAMLを使って、DockPanelを表示します。
普通のXAMLと、LastChildFill="False" を指定したXAMLです。

Blog: .NETな日々 ⇒ [WPF] WPF入門 ~レイアウト [DockPanel]~
http://blogs.wankuma.com/kzt/archive/2009/03/17/169777.aspx
を、参考にさせていただきました。[ .NETな日々 ]は良くできています。
サンプルが上手に使われていて、わかりやすいです。

#
# DockPanelTestFill.py

import clr
clr.AddReferenceByPartialName("PresentationFramework")
clr.AddReferenceByPartialName("PresentationCore")
from System import Object
from System.Windows import Window, Application
from System.Windows.Markup import XamlReader
xaml_str="""
<Window
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Window1" Height="300" Width="300"> 
    <DockPanel> 
        <Button DockPanel.Dock="Left">Left</Button> 
        <Button DockPanel.Dock="Top">Top</Button> 
        <Button DockPanel.Dock="Right">Right</Button> 
        <Button DockPanel.Dock="Bottom">Bottom</Button> 
        <Button DockPanel.Dock="Top">Fill</Button> 
    </DockPanel> 
</Window>
"""
class ExWindow(Object):
    def __init__(self):
        self.Root = win = XamlReader.Parse(xaml_str)
if __name__ == "__main__":
    win = ExWindow()
    Application().Run(win.Root)

#
# DockPanelTestNotFill.py
#
import clr
clr.AddReferenceByPartialName("PresentationFramework")
clr.AddReferenceByPartialName("PresentationCore")
from System import Object
from System.Windows import Window, Application
from System.Windows.Markup import XamlReader
xaml_str="""
<Window
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Window1" Height="300" Width="300"> 
    <DockPanel LastChildFill="False" > 
        <Button DockPanel.Dock="Left">Left</Button> 
        <Button DockPanel.Dock="Top">Top</Button> 
        <Button DockPanel.Dock="Right">Right</Button> 
        <Button DockPanel.Dock="Bottom">Bottom</Button> 
        <Button DockPanel.Dock="Top">Not Fill</Button> 
    </DockPanel> 
</Window>
"""
class ExWindow(Object):
    def __init__(self):
        self.Root = win = XamlReader.Parse(xaml_str)
if __name__ == "__main__":
    win = ExWindow()
    Application().Run(win.Root)

IronPythonの世界 (Windows Script Programming)
荒井 省三
ソフトバンク クリエイティブ
エキスパートPythonプログラミング
Tarek Ziade
アスキー・メディアワークス
Pythonスタートブック
辻 真吾
技術評論社

最新の画像もっと見る

コメントを投稿