Windows UWP开发系列 – RelativePanel
RelativePanel是在Windows 10 UWP程序中引入的一種新的布局面板,它是通過附加屬性設置元素間的位置關系來對實現布局的。一個簡單的示例如下:
<RelativePanel>
????<TextBox x:Name="textBox1" Text="textbox" Margin="5"/>
????<Button x:Name="blueButton" Margin="5" Background="LightBlue" Content="ButtonRight" RelativePanel.RightOf="textBox1"/>
????<Button x:Name="orangeButton" Margin="5" Background="Orange" Content="ButtonBelow" RelativePanel.RightOf="textBox1" RelativePanel.Below="blueButton"/>
</RelativePanel>
布局的效果如下:
????????
它支持如下幾種位置關系:
和其它元素相鄰:
- LeftOf
- RightOf
- Above
- Below
和其他元素邊緣對齊:
- AlignBottomWith
- AlignLeftWith
- AlignTopWith
- AlignRightWith
和其它元素中心對齊:
- AlignHorizontalCenterWith
- AlignVerticalCenterWith
和Panel邊緣對齊:
- AlignBottomWithPanel
- AlignLeftWithPanel
- AlignRightWithPanel
- AlignTopWithPanel
和Panel中心對齊:
- AlignHorizontalCenterWithPanel
- AlignVerticalCenterWithPanel
試用了一下,常用的對齊方式都有了,基本上各種復雜的布局都能輕易的實現。唯一的缺點是,這種布局方式和和其它元素耦合的,里面的元素不像其它的面板那樣可以隨意刪除。不過也非常強大了,比起之前WinRt下的那些布局面板要方便多了。
總結
以上是生活随笔為你收集整理的Windows UWP开发系列 – RelativePanel的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Delphi6 提示 Class TMS
- 下一篇: BGWN项目轶事之主导Global We