2013年1月3日木曜日

コンテンツ(Label)


Content機構には、2つの体系あり

  • ContentControl    単一エレメントを保持することができるContentと呼ばれるプロパティが含まれている
                                (自分の子供として単一エレメントを保持する)
       クラス定義は、

                Module Name: PresentationFramework.dll

          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

         単一エレメントを保持する「Content」プロパティは

                >   [System.Windows.Controls.ContentControl]::System.Object Content
                >   System.Windows.Controls.ContentControl]::System.Windows.DependencyProperty ContentProperty

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

        IsPublic IsSerial Name                           BaseType
        -------- -------- ----                                   --------
        True     False    Window                          System.Windows.Controls.ContentControl
        True     False    Label                             System.Windows.Controls.ContentControl
        True     False    ScrollViewer                    System.Windows.Controls.ContentControl
        True     False    ButtonBase                     System.Windows.Controls.ContentControl
        True     False    ListBoxItem                     System.Windows.Controls.ContentControl
        True     False    HeaderedContentControl System.Windows.Controls.ContentControl
        True     False    Frame                            System.Windows.Controls.ContentControl
        True     False    GroupItem                       System.Windows.Controls.ContentControl
        True     False    StatusBarItem                 System.Windows.Controls.ContentControl
        True     False    ToolTip                           System.Windows.Controls.ContentControl
        True     False    UserControl                     System.Windows.Controls.ContentControl


  • ItemsConrol       順序付けされているItemsと呼ばれる子供エレメント群を保持する
                              ことができるロパティ's が含まれている

       クラス定義は、
                Module Name: PresentationFramework.dll

           System.Windows.Controls.ItemsControl   <--これ
             System.Windows.Controls.Control
               System.Windows.FrameworkElement
                 System.Windows.UIElement
                   System.Windows.Media.Visual
                     System.Windows.DependencyObject
                       System.Windows.Threading.DispatcherObject
                         System.Object


         単一エレメントを保持する「Items」プロパティは

                    System.Type : System.Windows.Controls.ItemsControl


            >   [System.Windows.Controls.ItemsControl]::System.Windows.Controls.ItemCollection Items
            >   [System.Windows.Controls.ItemsControl]::System.Collections.IEnumerable ItemsSource
            >   [System.Windows.Controls.ItemsControl]::System.Windows.DependencyProperty ItemsSourceProperty



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

        IsPublic IsSerial Name                                       BaseType
        -------- -------- ----                                               --------
        True     False    MenuBase                                   System.Windows.Controls.ItemsControl
        True     False    HeaderedItemsControl                   System.Windows.Controls.ItemsControl
        True     False    Selector                                        System.Windows.Controls.ItemsControl
        True     False    DataGridCellsPresenter                  System.Windows.Controls.ItemsControl
        True     False    DataGridColumnHeadersPresenter System.Windows.Controls.ItemsControl
        True     False    StatusBar                                      System.Windows.Controls.ItemsControl
        True     False    TreeView                                      System.Windows.Controls.ItemsControl


Labelコントロール定義は以下の通り

     Module Name: PresentationFramework.dll

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


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



(画像として、C:\temp\work\turi04.jpgを準備)
---------------------------------------------
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"
        Width="400" Height="380">

    <StackPanel >
        <Label Content="初日の出と釣り" FontWeight="Bold"/>
        <Label>
            <Image Name="myImage" Source="何を入れても無駄"></Image> <!-- Imageの癖-->
        </Label>
    </StackPanel>

</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)
$form.findname("myImage").Source = "C:\temp\work\turi04.jpg"
[void]$Form.ShowDialog()
exit
--------------------------------------------------------------

Altキー+F、Altキー+Lで移動する

Altキー機能
--------------------------------------------------------------
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"
        Width="400" Height="380">

    <StackPanel >
        <Label Target="{Binding ElementName=firstName}">_First Name:</Label>
        <TextBox Name="firstName"></TextBox>
        <Label Target="{Binding ElementName=lastName}">_Last Name:</Label>
        <TextBox Name="lastName"></TextBox>
    </StackPanel>

</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 件のコメント:

コメントを投稿