代码一
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Height="100" Fill="Beige" Grid.Row="0" />
<Rectangle Grid.Row="1" Fill="SteelBlue" />
</Grid>
分析
<Grid>
是网格属性,在里面定义网格的行属性<Grid.RowDefinitions>
<Grid.RowDefinitions>
里面可以定义行的高度
Height = “Auto”为自由高度
Height = “*”为剩下的全部作为他的高度<Rectangle>
为矩形属性。
Height = "100"
定义矩形的高为100
Fill = "Beige"
定义矩形的填充色为beige色
Grid.Row = "0"
定义这个矩形的位置在网格的第一行
问题
Grid.Row
出现在了矩形属性中,但矩形的属性并不包含这个属性。所以它属于附属属性,至于为什么会有附属属性,请百度。
代码二
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="2*" />
<RowDefinition Height="3*" />
</Grid.RowDefinitions>
<Rectangle Fill="Red" Grid.Row="0" />
<Rectangle Fill="Blue" Grid.Row="1" />
<Rectangle Fill="Green" Grid.Row="2" />
</Grid>
分析
- 星号代表行高占据所有空余高度,1*就代表占用1/6大小的高
<Rectangle>
属性没有设置宽高,默认自动100%填充
问题
在UWP中可能会有不同分辨率的设备,所以我们要用比例来设定一些值可以让APP运行在不同的设备上也不至于变形。
版权声明:本文为sfeavh原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。