2014-07-01 7 views
0

안녕하세요 저는 WPF 프로그래밍을 처음 사용하고 있습니다. 내 창 너비와 높이에 따라 너비와 높이가있는 창이 있습니다.WPF에서 창 너비와 높이에 따라 컨트롤 너비와 높이를 조절하는 방법

TblWind.Height = System.Windows.SystemParameters.FullPrimaryScreenHeight; //(768) 
TblWind.Width = System.Windows.SystemParameters.FullPrimaryScreenWidth; //(1024) 

지금 내가 마찬가지로 2 열 각각의 폭이 창 내부에 그리드를 추가하지만, 창 높이에 기초의 높이와 너비를 조정하고, 즉 4 행을 폭하려는 각 창문 높이의 5 %를해야하고 창 칼럼

<Grid.RowDefinitions> 
     <RowDefinition Height=".5*" ></RowDefinition> 
     <RowDefinition Height=".5*"></RowDefinition> 
     <RowDefinition Height=".5*"></RowDefinition> 
     <RowDefinition Height=".5*"></RowDefinition> 

    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width=".5*"></ColumnDefinition> 
     <ColumnDefinition Width=".5*"></ColumnDefinition> 


</Grid.ColumnDefinitions> 
    <Label Grid.Row="0" Grid.Column="0" Content="Name:"></Label> 
    <Label Grid.Row="1" Grid.Column="0" Content="Name:"></Label> 
    <Label Grid.Row="2" Grid.Column="0" Content="Name:"></Label> 
    <Label Grid.Row="3" Grid.Column="0" Content="Name:"></Label> 
    <TextBox Grid.Row="0" Grid.Column="1" ></TextBox> 
    <TextBox Grid.Row="1" Grid.Column="1" ></TextBox> 
    <TextBox Grid.Row="2" Grid.Column="1" ></TextBox> 
    <TextBox Grid.Row="3" Grid.Column="1" ></TextBox> 
</Grid> 

5 %이어야하지만, 각각의 폭의 50 %를 가지고 2 개 부분 창폭 분할된다.

도와주세요.  

+0

다른 90 %의 창에 넣기를 원하십니까? – Bas

+0

다른 90 %의 창에 일부 컨트롤을 추가하려면 –

답변

1

비례 크기 조정은 모든 행 높이와 열 높이가 동일하다는 것을 의미합니다. 측정 된 크기의 비율이 아닙니다.

<RowDefinition Height="0.5*"/> 
<RowDefinition Height-"0.5*"/> 

다만 첫 번째 행의 크기의 50 %가 두 번째 행의 크기의 50 % 이상임을 의미한다. 즉, 높이가 동일합니다. 경우보다

다르지는 말했다 :

<RowDefinition Height="2*"/> 
<RowDefinition Height="2*"/> 

단지 첫 번째 행의 두 배 크기가 두 번째 행의 두 배 크기와 동일한 것을 의미한다.

그리드를 윈도우 높이의 상위 20 % (4 * 5 % = 20 %) 및 가장 왼쪽의 윈도우 폭 10 % (2 * 5 % = 10 %)로 제한하려면, 그런 다음 Grid에서 강제 실행하면 행과 열의 크기가 모두 동일해질 수 있습니다.

<Window> 

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 

     <Grid.RowDefinitions> 
      <RowDefinition Height="1*"/> <!-- 1/5th (20%) of the height --> 
      <RowDefinition Height="4*"/> 
     </Grid.RowDefinitions> 

     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="1*"/> <!-- 1/10th (10%) of the width --> 
      <ColumnDefinition Width="9*"/> 
     </Grid.ColumnDefinitions> 

     <!-- now we have a dedicated cell for your grid... --> 
     <Grid Grid.Row="0" Grid.Column="0"> 

      <Grid.RowDefinitions> 
       <RowDefinition/> 
       <RowDefinition/> 
       <RowDefinition/> 
       <RowDefinition/> 
      </Grid.RowDefinitions> 

      <Grid.ColumnDefinitions> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
      </Grid.ColumnDefinitions> 

      <!-- duplicate your content here... --> 

     </Grid> 

    </Grid> 

</Window> 
+0

아, 저를 때려주십시오. – Stuart

+0

그래도 똑같은 답변이므로 올바른 길을 가야합니다.) 환호하는 사람! –

관련 문제