2013年1月3日木曜日

レイアウト(コンテンツ配列)

コンテンツの管理クラスは?  Button例
        Module Name: PresentationFramework.dll

    System.Windows.Controls.Button
       System.Windows.Controls.Primitives.ButtonBase
         System.Windows.Controls.ContentControl <--★たぶんこれ!
           System.Windows.Controls.Control
             System.Windows.FrameworkElement
               System.Windows.UIElement
                 System.Windows.Media.Visual
                   System.Windows.DependencyObject
                     System.Windows.Threading.DispatcherObject
                       System.Object

「ContentControl」プロパティで整列に関係するもの <-- 「ContentAlignment」キーワード

    System.Type : System.Windows.Controls.ContentControl

[System.Windows.Controls.Control]::System.Windows.HorizontalAlignment HorizontalContentAlignment
[System.Windows.Controls.Control]::System.Windows.VerticalAlignment VerticalContentAlignment


①水平整列の設定値レパートリ調査

         System.Type : System.Windows.orizontalAlignment

[System.Windows.HorizontalAlignment]::System.Windows.HorizontalAlignment Left
[System.Windows.HorizontalAlignment]::System.Windows.HorizontalAlignment Center
[System.Windows.HorizontalAlignment]::System.Windows.HorizontalAlignment Right
[System.Windows.HorizontalAlignment]::System.Windows.HorizontalAlignment Stretch

②垂直整列の設定値レパートリ調査

System.Type : System.Windows.VerticalAlignment

[System.Windows.VerticalAlignment]::System.Windows.VerticalAlignment Top
[System.Windows.VerticalAlignment]::System.Windows.VerticalAlignment Center
[System.Windows.VerticalAlignment]::System.Windows.VerticalAlignment Bottom
[System.Windows.VerticalAlignment]::System.Windows.VerticalAlignment Stretch


実行してみる


  1. PowershellだけでWPF表示(Powershell3.0でも2.0でも稼働)
  2. .Netframeworkは3.0以上が必要
  3. WPFの約束としてPowershellはSTAモードで動く必要あり
  4. 以下コードを
      ①Powershellコンソールにコピペして実行
      ②ISEで実行する時はすでにSTAモードなので適時修正して実行
        注意:ブラウザによってはコピペで行頭に余分な空白が出来てしまうことあり
               C:\temp> □'@   ← ここの行の行頭に空白あると動かない 




---------------------------------------------
if ($host.Version.Major -eq 3) {
    powershell.exe
} else {
    if ($host.Runspace.ApartmentState -eq "STA") {return}
    powershell.exe -version 2 -sta
}

$xaml_win = @'
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="325" Width="280">

    <Canvas>
        <StackPanel Canvas.Left="12" Canvas.Top="12" Height="100" Width="109">
            <Button HorizontalContentAlignment="Left">左</Button>
            <Button HorizontalContentAlignment="Center">中央</Button>
            <Button HorizontalContentAlignment="Right">右</Button>
            <Button HorizontalContentAlignment="Stretch">拡張</Button>
        </StackPanel>

        <StackPanel Orientation="Horizontal" Height="66" Width="104" Canvas.Left="43" Canvas.Top="173">
            <Button VerticalContentAlignment="Top">上</Button>
            <Button VerticalContentAlignment="Center">中央</Button>
            <Button VerticalContentAlignment="Bottom">底</Button>
            <Button VerticalContentAlignment="Stretch">拡張</Button>
        </StackPanel>
    </Canvas>

</Window>
'@  # <--ブラウザによっては、コピペ時に行頭に空白出来る。空白削除する必要あり

if ($host.Version.Major -eq 3) {
    add-type -assembly WindowsBase,PresentationCore,PresentationFramework,System.Xml,System.Xaml
} else {
    add-type -assembly WindowsBase,PresentationCore,PresentationFramework,System.Xml
}

$form = [System.Windows.Markup.XamlReader]::Parse($xaml_win)
[void]$Form.ShowDialog()
exit
--------------------------------------------------------------

0 件のコメント:

コメントを投稿