LoginSignup
0
1

More than 5 years have passed since last update.

Visual Studio / WPF > コントロール > StackPanel > コントロールの整列に使う

Last updated at Posted at 2017-04-23
動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

@ WPF 4.5入門 by 大田一希さん
No.1805 / 9985

StackPanelコントロールは、子要素を縦方向または横方向に一列に並べるコントロールです。

試してみた。

XAML
<Window x:Class="_170423_t1935_border.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:_170423_t1935_border"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top"
                    Height="229" Margin="27,29,0,0"  Width="345" Background="#FF84A4F7">
            <Button Content="Button" Height="33" Margin="10,0,30,0" Width="90" 
                    HorizontalContentAlignment="Center" HorizontalAlignment="Left"/>
            <Button Content="Button" Height="33" Margin="10,0,30,0" Width="90" 
                    HorizontalContentAlignment="Center" HorizontalAlignment="Right"/>
            <Button Content="Button" Height="33" Margin="10,0,30,0" Width="90" 
                    HorizontalContentAlignment="Center" HorizontalAlignment="Left"/>
        </StackPanel>
    </Grid>
</Window>

work.png

HorizontalAlignmentとVerticalAlignmentでコントロールの配置を扱うようだ。
Marginで設定したものが端になる。

orientaion

orientationを設定することで、配置を横方向にすることもできる。

@ WPF 4.5入門 by 大田一希さん
No.1853 / 9985

buttanで試してみた。

XAML
<Window x:Class="_170423_t1935_border.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:_170423_t1935_border"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel Orientation="Horizontal"
                    HorizontalAlignment="Left" VerticalAlignment="Top"
                    Height="229" Margin="27,29,0,0"  Width="345" Background="#FF84A4F7">
            <Button Content="Button" Height="33" Margin="0,0,0,0" Width="90" 
                    HorizontalContentAlignment="Center" VerticalAlignment="Top"/>
            <Button Content="Button" Height="33" Margin="0,0,0,0" Width="90" 
                    HorizontalContentAlignment="Center" VerticalAlignment="Bottom"/>
            <Button Content="Button" Height="33" Margin="0,0,0,0" Width="90" 
                    HorizontalContentAlignment="Center" VerticalAlignment="Center"/>
        </StackPanel>
    </Grid>
</Window>

work.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1