2013年1月5日土曜日

コンテンツ(Window1)


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 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

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


Windowクラスについて調べる

        クラスの定義は以下の通り

            Module Name: PresentationFramework.dll

       System.Windows.Window
         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

        有益なメソッド
    >   void Show()            Windowを表示する。即処理が戻ってくる
    >   Bool ShowDialog()   Windowを表示する。Closeするまで処理は戻ってこない
    >   Hide()                      Windowを見えなくする

        有益なプロパティ
    >   Topmost                            Bool                                                           最前面に表示
    >   ShowInTaskBar                 Bool                                                           タスクバーにリストする
    >   WindowStartupLocation   "Manual","CenterScreen","CenterOwner" 表示位置
    >   Owner System.Windows.Window                                                  子供Win側で親Winを指定


実際に使ってみる

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

Windowプロパティの確認
---------------------------------------------
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="250" Width="325">

    <DockPanel>
        <Button Content="Windowプロパティの確認" Name="myButton" DockPanel.Dock="Top"/>
        <TextBox Name="myTextBox" FontSize="16" Foreground="Red" MaxLines="15" />
    </DockPanel>

</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.Topmost = $True
$form.ShowInTaskBar = $True
$form.WindowStartupLocation = @("Manual","CenterScreen","CenterOwner")[1]

[void]$Form.ShowDialog()
exit
--------------------------------------------------------------


Windowの親子関係の例
--------------------------------------------------------------
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="150" Width="250">

    <Grid>
        <Button Name="myButton" VerticalAlignment="Top">
            他のWindowを生成
        </Button>
    </Grid>

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

$code = @'
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace MyButton
{
    public class EventTest : Window
    {
        public void subscribe(Button b)
        {
            b.Click += Button_Click1;
        }

        public void Button_Click1(object sender, RoutedEventArgs e)
        {
            Window w1 = new Window(); w1.Background = Brushes.AliceBlue;
            w1.Title = "Win 1"; w1.Height = 150; w1.Width = 200;
            w1.Content = "独立Window";
            w1.Show();

            Window w2 = new Window(); w2.Background = Brushes.PaleVioletRed;
            w2.Title = "Win 2"; w2.Height = 150; w2.Width = 200;
            w2.Content = "依存Window(子供)";
            w2.Owner = this; // ★ このWindowを子供指定
            w2.Show();
        }
    }
}
'@  # <--ブラウザによっては、コピペ時に行頭に空白出来る。空白削除する必要あり

if ($host.Version.Major -eq 3) {
    Add-Type $code -ReferencedAssemblies @("WindowsBase","PresentationCore","PresentationFramework","System.Xaml")
} else {
    Add-Type $code -ReferencedAssemblies @("WindowsBase","PresentationCore","PresentationFramework")
}
$form = [System.Windows.Markup.XamlReader]::Parse($xaml_win)
$mb = New-Object MyButton.EventTest
$mb.subscribe($form.FindName("myButton"))
$mb.show()
[void]$Form.ShowDialog()
exit
--------------------------------------------------------------

2013年1月4日金曜日

コンテンツ(CheckBox, RadioButton)


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 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
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


CheckBoxとRaidoBoxの調査

      CheckBoxクラスの定義は以下の通り

                Module Name: PresentationFramework.dll

           System.Windows.Controls.CheckBox
             System.Windows.Controls.Primitives.ToggleButton
               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


      RadioButtonクラスの定義は以下の通り


                Module Name: PresentationFramework.dll

           System.Windows.Controls.RadioButton
             System.Windows.Controls.Primitives.ToggleButton
               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


実際に使ってみる

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

 自動グループ化(RadioButton) ← (標準)同じ親を持つ兄弟ボタンを同一グループ化

---------------------------------------------
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>
        <CheckBox Name="cb1" Margin="5,10,0,0">Option 1</CheckBox>
        <CheckBox Name="cb2" Margin="5,0,0,0">Option 2</CheckBox>
        <RadioButton Name="rb1" Margin="5,10,0,0">One of Three</RadioButton>
        <RadioButton Name="rb2" Margin="5,0,0,0">Two of Three</RadioButton>
        <RadioButton Name="rb3" Margin="5,0,0,0">Three of Three</RadioButton>
    </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
--------------------------------------------------------------
★CheckBox、RadioButtonのそれぞれの「Content」プロパティは以下のようになっている
> 0..4 | % { ($Form.Content.Children)[$_].Content }
                Option 1
                Option 2
                One of Three
                Two of Three
                Three of Three


グループ化の指定
--------------------------------------------------------------
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>
        <RadioButton Margin="5,0,5,0">Default 1</RadioButton>
        <RadioButton Margin="5,0">Default 2</RadioButton>
        <RadioButton GroupName="Group1" Margin="5,7,5,0">Group1-1</RadioButton>
        <RadioButton GroupName="Group1" Margin="5,0">Group1-2</RadioButton>
        <RadioButton GroupName="Group2" Margin="5,7,5,0">Group2-1</RadioButton>
        <RadioButton GroupName="Group2" Margin="5,0">Group2-2</RadioButton>
    </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
--------------------------------------------------------------
★RadioButtonのそれぞれの「Content」プロパティは以下ようになっている
> 0..5 | % { ($Form.Content.Children)[$_].Content }
                Default 1
                Default 2
                Group1-1
                Group1-2
                Group2-1
                Group2-2

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
--------------------------------------------------------------

レイアウト(UniformGrid)


Panelはエレメントを種々の形に並べて配置するコンテナの役割をするエレメント

Panelから拡張されるクラスの一覧は以下の通り

 > [System.Windows.Controls.Panel]  をBaseTypeとするもの

  IsPublic IsSerial Name                        BaseType
  --------   --------  ----                             --------
  True     False    StackPanel                 System.Windows.Controls.Panel     積み重ね配置
  True     False    WrapPanel                  System.Windows.Controls.Panel     次の行/列へ折り返す配置
  True     False    DockPanel                  System.Windows.Controls.Panel     互いに引っ付いた配置
  True     False    Grid                             System.Windows.Controls.Panel     格子状の配置
  True     False    Canvas                       System.Windows.Controls.Panel     画布に描く配置
  True     False    UniformGrid                 System.Windows.Controls.Panel     Gridの簡素なやつ
  True     False    TabPanel                    System.Windows.Controls.Panel     WebのTab的な配置
  True     False    ToolBarOverflowPanel System.Windows.Controls.Panel     WebのToolBar的
  True     False    VirtualizingPanel           System.Windows.Controls.Panel     Webの縦Panel的


UniformGrid
    Gridの超シンプル版みたいなやつ(均等配置、順番固定、単一コンテンツ)
    まあ十分な時もあるかも


実際に確認してみる


  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="GridWindow" Height="150" Width="300">

    <UniformGrid Rows="2" Columns="2">
        <Button>Button 1</Button>
        <Button>Button 2</Button>
        <Button>Button 3</Button>
        <Button>Button 4</Button>
    </UniformGrid>

</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
--------------------------------------------------------------

レイアウト(Canvas:3次元)


Panelはエレメントを種々の形に並べて配置するコンテナの役割をするエレメント

Panelから拡張されるクラスの一覧は以下の通り

 > [System.Windows.Controls.Panel]  をBaseTypeとするもの

  IsPublic IsSerial Name                        BaseType
  --------   --------  ----                             --------
  True     False    StackPanel                 System.Windows.Controls.Panel     積み重ね配置
  True     False    WrapPanel                  System.Windows.Controls.Panel     次の行/列へ折り返す配置
  True     False    DockPanel                  System.Windows.Controls.Panel     互いに引っ付いた配置
  True     False    Grid                             System.Windows.Controls.Panel     格子状の配置
  True     False    Canvas                       System.Windows.Controls.Panel     画布に描く配置
  True     False    UniformGrid                 System.Windows.Controls.Panel     Gridの簡素なやつ
  True     False    TabPanel                    System.Windows.Controls.Panel     WebのTab的な配置
  True     False    ToolBarOverflowPanel System.Windows.Controls.Panel     WebのToolBar的
  True     False    VirtualizingPanel           System.Windows.Controls.Panel     Webの縦Panel的


Canvas  Z-Order(3次元)の表現
    Canvas.ZIndex  アタッチドプロパティにより指定できる
        ①ZIndex値の大きいほうが前
        ②同じ値の時は後に定義した方が前
        ③ZIndex省略時の値はゼロ


実際に確認してみる

  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="GridWindow" Height="160" Width="160">

    <Canvas>
        <Button Canvas.Top="32" Canvas.Left="30" Canvas.ZIndex="5">Top Left</Button>
        <Button Canvas.Top="20" Canvas.Right="30">Top Right</Button>
    </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
--------------------------------------------------------------

レイアウト(Canvas:基本)


Panelはエレメントを種々の形に並べて配置するコンテナの役割をするエレメント

Panelから拡張されるクラスの一覧は以下の通り

 > [System.Windows.Controls.Panel]  をBaseTypeとするもの

  IsPublic IsSerial Name                        BaseType
  --------   --------  ----                             --------
  True     False    StackPanel                 System.Windows.Controls.Panel     積み重ね配置
  True     False    WrapPanel                  System.Windows.Controls.Panel     次の行/列へ折り返す配置
  True     False    DockPanel                  System.Windows.Controls.Panel     互いに引っ付いた配置
  True     False    Grid                             System.Windows.Controls.Panel     格子状の配置
  True     False    Canvas                       System.Windows.Controls.Panel     画布に描く配置
  True     False    UniformGrid                 System.Windows.Controls.Panel     Gridの簡素なやつ
  True     False    TabPanel                    System.Windows.Controls.Panel     WebのTab的な配置
  True     False    ToolBarOverflowPanel System.Windows.Controls.Panel     WebのToolBar的
  True     False    VirtualizingPanel           System.Windows.Controls.Panel     Webの縦Panel的


Canvas基本形

Canvasエレメントの指定の座標から絶対値で内部に置くコントロールを指定する
    ・Canvas.Left    ="nnn"
    ・Canvas.Right   ="mmm"
    ・Canvas.Top     ="xxx"
    ・Canvas.Bottom="yyy"


実際に確認してみる


  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="GridWindow" Height="180" Width="400">

<Canvas>
<Button Canvas.Top="20" Canvas.Left="30">Top Left</Button>
<Button Canvas.Top="20" Canvas.Right="30">Top Right</Button>
<Button Canvas.Bottom="20" Canvas.Left="30">Bottom Left</Button>
<Button Canvas.Bottom="20" Canvas.Right="30">Bottom Right</Button>
</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
--------------------------------------------------------------

レイアウト(Grid:共有グループ)


Panelはエレメントを種々の形に並べて配置するコンテナの役割をするエレメント

Panelから拡張されるクラスの一覧は以下の通り

 > [System.Windows.Controls.Panel]  をBaseTypeとするもの

  IsPublic IsSerial Name                        BaseType
  --------   --------  ----                             --------
  True     False    StackPanel                 System.Windows.Controls.Panel     積み重ね配置
  True     False    WrapPanel                  System.Windows.Controls.Panel     次の行/列へ折り返す配置
  True     False    DockPanel                  System.Windows.Controls.Panel     互いに引っ付いた配置
  True     False    Grid                             System.Windows.Controls.Panel     格子状の配置
  True     False    Canvas                       System.Windows.Controls.Panel     画布に描く配置
  True     False    UniformGrid                 System.Windows.Controls.Panel     Gridの簡素なやつ
  True     False    TabPanel                    System.Windows.Controls.Panel     WebのTab的な配置
  True     False    ToolBarOverflowPanel System.Windows.Controls.Panel     WebのToolBar的
  True     False    VirtualizingPanel           System.Windows.Controls.Panel     Webの縦Panel的


共有サイズグループの指定

  • Gridの定義用クラスに「SharedSizeGroup」機能というのがある

    同じ名前のグループ同士のCellは、同じサイズにリアルタイムでサイズを連動させてくれる。


  • 共有サイズグループの有効化
                System.Type : System.Windows.Controls.Grid

        [System.Windows.Controls.Grid]::Void SetIsSharedSizeScope(System.Windows.UIElement, Boolean)
        [System.Windows.Controls.Grid]::Boolean GetIsSharedSizeScope(System.Windows.UIElement)
        [System.Windows.Controls.Grid]::System.Windows.DependencyProperty IsSharedSizeScopeProperty


  • 「SharedSizeGroup」プロパティ
              System.Type : System.Windows.Controls.ColumnDefinition

        [System.Windows.Controls.DefinitionBase]::System.String get_SharedSizeGroup()
        [System.Windows.Controls.DefinitionBase]::Void set_SharedSizeGroup(System.String)
       [System.Windows.Controls.DefinitionBase]::System.String SharedSizeGroup



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


「A」と「D」が共有サイズグループ
---------------------------------------------
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="GridWindow" Height="180" Width="400">

        <Grid Grid.IsSharedSizeScope="True">
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="Clumn0"></ColumnDefinition>
                <ColumnDefinition Width="50"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="Auto" SharedSizeGroup="Clumn0"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Button Grid.Row="0" Grid.Column="0">A</Button>
            <Button Grid.Row="0" Grid.Column="1">B</Button>
            <Button Grid.Row="0" Grid.Column="2">C</Button>
            <Button Grid.Row="0" Grid.Column="3">D</Button>
            <Button Grid.Row="0" Grid.Column="4">Other Text</Button>
        </Grid>

</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
--------------------------------------------------------------