11

WPFを初めて使用し、オンラインチュートリアルを学習して、いくつか質問があります。

(1)1つのWPFグリッドセルに、幅の異なる複数のボタンを並べて表示しようとしています。ただし、それらは常に互いに積み重なっているように見えます。私は何を見逃していますか?

(2)グリッドセル内の各ボタンの絶対開始左位置を制御することは可能ですか?

ありがとう。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<ScrollViewer>
    <Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          ShowGridLines ="True" >
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="60*" />
        </Grid.ColumnDefinitions>

        <Button Content="Button No. 1" Grid.Row="0" Grid.Column="0" />

        <GridSplitter HorizontalAlignment="Center" Width="6"
                      Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" />

        <Button Content="Button No. 4-2" Grid.Row="0" Grid.Column="2" Width="100" />
        <Button Content="Button No. 4-1" Grid.Row="0" Grid.Column="2" Width="50" />

    </Grid>
</ScrollViewer>
</Page>

サルバドールからの回答に基づいて、これは機能します:

        <Button VerticalAlignment="Top" HorizontalAlignment="Left" Content="Button No. 1" Grid.Row="0" Grid.Column="0" Height="100"/>

        <GridSplitter HorizontalAlignment="Center" Width="6"
                      Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" />

        <Button VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0" Content="Button No. 4-2" Grid.Row="0" Grid.Column="2" Height="100" Width="100" />
        <Button VerticalAlignment="Top" HorizontalAlignment="Left" Margin="400,0,0,0" Content="Button No. 4-1" Grid.Row="0" Grid.Column="2" Height="150" Width="50" />

ありがとう!

4

2 に答える 2

12

VerticalAlignmentまたはプロパティを設定していないHorizontalAlignmentため、デフォルトでは中央に配置されます。

Marginこれらのプロパティを設定し、wpf 要素のプロパティと組み合わせて使用​​する必要があります。

このWPFレイアウトの紹介を見てください

于 2012-04-12T21:19:56.640 に答える
9

コンテナ コントロール( CanvasDockPanelStackPanelなど)の 1 つをグリッド位置 (Row # + Column #) で使用し、そこにコントロールを配置することができます。

これにより、1 つのグリッド位置に複数のコントロールを簡単にレイアウトできます。

于 2012-04-12T21:19:09.837 に答える