UWP-RelativePanel使用詳解

Windows 10已于7月29號面向全球發布,同時Universal Windows Platform(UWP) SDK也已正式放出,配合VS2015我們可以開發出通用的Windows App。
在Windows 10 SDK中,新增和改變了很多特性,其中用于適配的新控件RelativePanel將會成為我們開發中最常用的Windows 10組件。

RelativePanel

代碼示例:

<RelativePanel BorderBrush="Gray" BorderThickness="10"> 
<Rectangle x:Name="RedRect" Fill="Red" MinHeight="100" MinWidth="100"/> 
<Rectangle x:Name="BlueRect" Fill="Blue" MinHeight="100" MinWidth="100" RelativePanel.RightOf="RedRect" /> 
<!-- Width is not set on the green and yellow rectangles. It's determined by the RelativePanel properties. --> 
<Rectangle x:Name="GreenRect" Fill="Green" MinHeight="100" Margin="0,5,0,0" RelativePanel.Below="RedRect" RelativePanel.AlignLeftWith="RedRect" RelativePanel.AlignRightWith="BlueRect"/> 
<Rectangle Fill="Yellow" MinHeight="100" RelativePanel.Below="GreenRect" RelativePanel.AlignLeftWith="BlueRect" RelativePanel.AlignRightWithPanel="True"/</RelativePanel>

特性詳解:
開發中我們主要使用RelativePanel作為容器,使用RelativePanel的附加屬性對其內容進行布局,例如RightOf、Above等,用法與Grid的附加屬性類似。同時這些附加屬性與iOS中新特性AutoLayout的約束很像,下面是對其附加屬性詳細解釋。

用法 描述
RelativePanel.Above 設置當前element為目標element的上方
RelativePanel.AlignBottomWith 設置當前element與目標element底部對齊
RelativePanel.AlignBottomWithPanel 設置當前element與RelativePanel底部對齊
RelativePanel.AlignHorizontalCenterWith 設置當前element與目標element水平中心對齊
RelativePanel.AlignHorizontalCenterWithPanel 設置當前element與RelativePanel水平中心對齊
RelativePanel.AlignLeftWith 設置當前element與目標element左邊框對齊
RelativePanel.AlignLeftWithPanel 設置當前element與RelativePanel左邊框對齊
RelativePanel.AlignRightWith 設置當前element與目標element右邊框對齊
RelativePanel.AlignRightWithPanel 設置當前element與RelativePanel右邊框對齊
RelativePanel.AlignTopWith 設置當前element與目標element頂部對齊
RelativePanel.AlignTopWithPanel 設置當前element與RelativePanel頂部對齊
RelativePanel.AlignVerticalCenterWith 設置當前element與目標element垂直中心對齊
RelativePanel.AlignVerticalCenterWithPanel 設置當前element與RelativePanel垂直中心對齊
RelativePanel.Below 設置當前element為目標element的下方
RelativePanel.LeftOf 設置當前element為目標element的左邊
RelativePanel.RightOf 設置當前element為目標element的右邊

總結
RelativePanel能夠實現幾乎所有針對布局的約束,能夠滿足各種布局需求,配合VisualStateTrigger能夠較完美的視線響應式的UI,滿足Windows 10設想的小至IoT設備大至80寸Hub的應用情景。

原文轉自:msp的昌偉哥哥

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,813評論 25 708
  • 發現 關注 消息 iOS 第三方庫、插件、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 12,180評論 4 61
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,837評論 18 139
  • 前幾天像打仗一樣,忙忙碌碌,今天略消停,陪父母跑了趟醫院復查,一切安好。 簡書一直落后于滴答的指針,補作業的滋味真...
    息清港灣閱讀 304評論 0 0
  • 說真的,喜歡上一個人真的好難。 假裝微笑假裝堅強假裝快樂。 你知不知道,面具戴久了會變成皮。 明明不是一個人,你明...
    楚清朗閱讀 569評論 0 0