2012-04-12 19 views
4

新で複数のコントロールを持つ、オンラインチュートリアルをlearingと質問のカップルを持っている:1つのWPFグリッドセル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

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

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

これを見てIntroduction to WPF Layout

+0

完璧な、私の望むように動作します: – Shawn

6

あなたは、グリッド位置(行#+コラム#)で(StackPanelDockPanelCanvasのような)Container Controlsのいずれかを使用し、そのにあなたのコントロールを配置することをお勧めします。

これにより、1つのグリッド位置に複数のコントロールを配置する方がはるかに簡単になります。

関連する問題