2013年1月6日日曜日

コンテンツ(GroupBox)




HeaderedContentControlクラス

クラス定義は、

    Module Name: PresentationFramework.dll

System.Windows.Controls.HeaderedContentControl
 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

 このクラスはコンテンツを保持するプロパティを2つ持つ

    「ContentControl」クラスが元々持っているもの
        >   [System.Windows.Controls.ContentControl]::System.Object get_Content()
        >   [System.Windows.Controls.ContentControl]::Void set_Content(System.Object)
        >   [System.Windows.Controls.ContentControl]::System.Object Content
        >   [System.Windows.Controls.ContentControl]::System.Windows.DependencyProperty ContentProperty

    「HearderedCotentControl」クラスで追加されたもの(上記Contentのタイトル表記)
        >   [System.Windows.Controls.HeaderedContentControl]::Void set_Header(System.Object)
        >   [System.Windows.Controls.HeaderedContentControl]::Boolean get_HasHeader()
        >   [System.Windows.Controls.HeaderedContentControl]::System.Object Header
   >   [System.Windows.Controls.HeaderedContentControl]::System.Windows.DependencyProperty HeaderProperty

「HearderedCotentControl」から派生するクラスの一覧は?

        IsPublic IsSerial Name     BaseType
        -------- -------- ----     --------
        True     False    GroupBox System.Windows.Controls.HeaderedContentControl
        True     False    Expander System.Windows.Controls.HeaderedContentControl
        True     False    TabItem  System.Windows.Controls.HeaderedContentControl


GroupBoxについて   <--以下の2つを同時に実現

  • 1つのコンテンツを保持する
  • そのコンテンツのヘッダー情報を保持すること

実際に使ってみる

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

文字ヘッダーと画像ヘッダーの例
GroupBoxの動作確認
#-------------------------------------------------------
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="GroupBox調査" Height="220" Width="250">

    <GroupBox Header="Grouped Things" Margin="5">
        <StackPanel>
            <Image Margin="3" HorizontalAlignment="Left" Height="50" Source="c:\temp\work\photo.jpg">
            </Image>
            <Button Margin="3">ボタン1</Button>
            <Button Margin="3">ボタン2</Button>
        </StackPanel>
    </GroupBox>
    <!--
    <GroupBox Margin="5">
        <GroupBox.Header>
        <Image Margin="3" HorizontalAlignment="Left" Height="50" Source="c:\temp\work\photo.jpg">
        </Image>
        </GroupBox.Header>
        <StackPanel>
            <Button Margin="3">ボタン1</Button>
            <Button Margin="3">ボタン2</Button>
        </StackPanel>
    </GroupBox>
    -->
</Window>
'@  # <--ブラウザによっては、コピペ時に行頭に空白出来る。空白削除する必要あり

#-------------------------------------------------------
if ($host.Version.Major -eq 3) {
Add-Type -AssemblyName WindowsBase,PresentationCore,PresentationFramework,system.xml,System.Xaml
} else {
Add-Type -AssemblyName WindowsBase,PresentationCore,PresentationFramework,system.xml
}
$form = [System.Windows.Markup.XamlReader]::Parse($xaml_win)
[void]$form.showdialog()
exit



0 件のコメント:

コメントを投稿