嗨,我是WPF编程的新手。我有一个窗口,其宽度和高度根据我的窗口的宽度和高度而定。
TblWind.Height = System.Windows.SystemParameters.FullPrimaryScreenHeight; //(768)
TblWind.Width = System.Windows.SystemParameters.FullPrimaryScreenWidth; //(1024)
现在我要在此窗口中添加Grid,但要根据窗口的高度和宽度(即4行)调整其高度和宽度,每行应仅占窗口高度的5%类似地,每2列宽度应为窗口列的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>
但是它将窗口宽度分为两部分,每部分占宽度的50%。
请帮忙。
您的比例大小只是意味着所有行高和列高都将相同。它不是测量尺寸的百分比。
IE
<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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句