RelativePanel
RelativePanel
已在 Windows 10 中引入,主要用于支持自适应布局,其中面板的子元素根据可用空间的不同布局。RelativePanel
通常用于视觉状态 ,用于切换布局配置,适应屏幕或窗口大小,方向或用例。子元素使用附加属性来定义它们相对于面板和彼此的位置。
<RelativePanel
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<Rectangle
x:Name="rectangle1"
RelativePanel.AlignLeftWithPanel="True"
Width="360"
Height="50"
Fill="Red"/>
<Rectangle
x:Name="rectangle2"
RelativePanel.Below="rectangle1"
Width="360"
Height="50"
Fill="Green" />
</RelativePanel>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<!--VisualState to be triggered when window width is >=720 effective pixels.-->
<AdaptiveTrigger
MinWindowWidth="720" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter
Target="rectangle2.(RelativePanel.Below)"
Value="{x:Null}" />
<Setter
Target="rectangle2.(RelativePanel.RightOf)"
Value="rectangle1" />
<Setter
Target="rectangle1.(RelativePanel.AlignLeftWithPanel)"
Value="False" />
<Setter
Target="rectangle1.(RelativePanel.AlignVerticalCenterWithPanel)"
Value="True" />
<Setter
Target="rectangle2.(RelativePanel.AlignVerticalCenterWithPanel)"
Value="True" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>