2012-04-12 2 views
4

새로운 여러 컨트롤을 갖는 온라인 자습서를 통해 learing과 몇 가지 질문이 있습니다하나의 WPF 그리드 셀 WPF에

(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

당신은 그리드 위치에 Container Controls 중 하나 (DockPanel, Canvas 유사한, StackPanel)를 사용 (행 # + 열 번호) 및 그로 컨트롤을 배치 할 수 있습니다.

이렇게하면 단일 그리드 위치에 두 개 이상의 컨트롤을 배치하는 것이 훨씬 쉬워집니다.