2012年2月24日金曜日

StackPanel コントロール

コントロールを積み重ねて配置する。

<Window x:Class="WpfApplication.Window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window" Height="300" Width="300">
    <StackPanel Orientation="Horizontal">
        <StackPanel Width="138">
            <Label>あいうえお</Label>
            <Label>かきくけこ</Label>
            <Label>さしすせそ</Label>
            <Label>たちつてと</Label>
        </StackPanel>
        <StackPanel Width="138">
            <Button>なにぬねの</Button>
            <Button>はひふへほ</Button>
            <Button>まみむめも</Button>
            <Button>や ゆ よ</Button>
        </StackPanel>
    </StackPanel>
</Window>
Orientationでコントロールの方向を指定することが出来る。

2012年2月9日木曜日

Canvas コントロール

コントロールを座標指定して配置する。

<Window x:Class="WpfApplication2.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window3" Height="300" Width="300">
    <Canvas>
        <Line X1="20" Y1="20" X2="100" Y2="100" Stroke="Red" 
              StrokeStartLineCap="Round" StrokeThickness="10"/>
        <Line Canvas.Top="100" Canvas.Left="100" 
              X1="20" Y1="20" X2="100" Y2="100"
              Stroke="Red" StrokeEndLineCap="Round" StrokeThickness="10"/>
        <Rectangle Canvas.Top="100" Canvas.Left="0" Width="100" Height="100"
                   Fill="AliceBlue" Stroke="Red" StrokeThickness="1"/>
        <Ellipse Canvas.Top="0" Canvas.Left="100" Width="100" Height="100" 
                 Fill="Snow" Stroke="Black"/>
    </Canvas>
</Window>
Canvas.Top,Canvas.Left,Canvas.Right,Canvas.Bottomで指定することが出来る。

2012年2月7日火曜日

UniformGrid コントロール

行列表示。コントロールを記述した順に配置する。
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="280" Width="300">
    <UniformGrid Columns="7" Rows="5" FirstColumn="3" FlowDirection="LeftToRight" >
        <UniformGrid.Resources>
            <Style TargetType="Label">
                <Setter Property="BorderBrush" Value="Black"/>
                <Setter Property="BorderThickness" Value=".1"/>
            </Style>
        </UniformGrid.Resources>
        <Label>1</Label><Label>2</Label><Label>3</Label>
        <Label>4</Label><Label>5</Label><Label>6</Label>
        <Label>7</Label><Label>8</Label><Label>9</Label>
        <Label>10</Label><Label>11</Label><Label>12</Label>
        <Label>13</Label><Label>14</Label><Label>15</Label>
        <Label>16</Label><Label>17</Label><Label>18</Label>
        <Label>19</Label><Label>20</Label><Label>21</Label>
        <Label>22</Label><Label>23</Label><Label>24</Label>
        <Label>25</Label><Label>26</Label><Label>27</Label>
        <Label>28</Label><Label>29</Label>
    </UniformGrid>
</Window>
Columnsで列数。Rowsで行数を設定。
FirstColumnで値を設定するカラムインデックスを設定。
FlowDirectionでコントロールを当てはめていく方向を設定。

2012年2月5日日曜日

Grid コントロール

行列表示。コントロールを行列番号を指定して任意に配置することが出来る。
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="2*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0">祇園精舎の鐘の声</Label>
        <Label Grid.Row="1" Grid.Column="1">諸行無常の響きあり</Label>
    </Grid>
</Window>
Grid.RowDefinitionsで行の設定。
RowDefinitionの数が行数となる。高さなどを指定することが出来る。

Grid.RowDefinitionsで列の設定。
ColumnDefinitionの数が列数となる。幅などを指定することが出来る。

*は可変指定。他の可変行列を考慮した値が自動計算される。
Autoは内容により値が自動計算される。

Grid.Rowで行、Grid.Columnで列を指定して表示させることが出来る。
行列のIndexは0から始まる。

2012年2月4日土曜日

コンテナ コントロール

色々なコンテナ コントロールが存在する。

Grid - 行列表示。コントロールを行列番号を指定して任意に配置することが出来る。
UniformGrid - 行列表示。コントロールを記述した順に配置する。
Canvas - コントロールを座標指定して配置する。
StackPanel - コントロールを積み重ねて配置する。
WrapPanel - 配置したコントロールが領域外にはみ出す場合、自動で改行する。
DockPanel -
TabControl -

2012年2月3日金曜日

WPFのはじめ

Visual Studio起動。ファイル→新規作成→プロジェクト→WPF アプリケーションで作成。

XAMLファイルにてデザイン編集を行うことが出来る。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
    </Grid>
</Window>
WindowタグがC#でいうフォームの変わり。
Gridがフォーム上に配置したパネルみたいなもの。コンテナ コントロールというらしい。