UWP RelativePanel计划一个元素直接到另一个元素然后拉伸到面板

时间:2017-09-27 00:45:59

标签: xaml uwp uwp-xaml relativepanel

这是我的XAML

<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,0,0,0">
    <TextBlock x:Name="PageTitle"
               RelativePanel.AlignTopWithPanel="True"
               Style="{StaticResource WindowTitle}">This is my page title</TextBlock>
    <TextBlock x:Name="ActivityLabel"
               RelativePanel.Below="PageTitle"
               Style="{StaticResource CaptionTitle}">Activity</TextBlock>
    <ComboBox x:Name="ActivityOptions"
              RelativePanel.RightOf="ActivityLabel"
              RelativePanel.AlignRightWithPanel="True"
              RelativePanel.AlignHorizontalCenterWith="ActivityLabel"
              ItemsSource="{Binding Path=SupportedActivityTypes}">
    </ComboBox>
</RelativePanel>

这是我的输出 enter image description here

我想要实现的是标题位于页面顶部,标题下方有多行。每行都有一个标题,标题右边是组合框,文本框等,但右侧应该伸展到面板的右边框。

显然我的代码不起作用,组合甚至没有像我在标记中指定的那样与我的标题文本集中对齐。如何让组合的左侧触摸标题文本并将右侧触摸到面板的边框?

2 个答案:

答案 0 :(得分:1)

我想通了,我需要关注XAML

<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,0,0,0">
    <TextBlock x:Name="PageTitle"
               Margin="0,0,0,20"
               RelativePanel.AlignTopWithPanel="True"
               Style="{StaticResource WindowTitle}">This is page title</TextBlock>
    <TextBlock x:Name="ActivityLabel"
               RelativePanel.Below="PageTitle"
               Style="{StaticResource CaptionTitle}">Activity</TextBlock>
    <ComboBox x:Name="ActivityOptions"
              Margin="10,0,0,0"
              HorizontalAlignment="Stretch"
              RelativePanel.RightOf="ActivityLabel"
              RelativePanel.AlignRightWithPanel="True"
              RelativePanel.AlignVerticalCenterWith="ActivityLabel"
              ItemsSource="{Binding Path=SupportedActivityTypes}">
    </ComboBox>
</RelativePanel>

组合框位于标题标签的同一行(&#34;活动&#34;),同时宽度延伸到相对面板大小。

答案 1 :(得分:0)

  

如何让组合的左侧触摸标题文本并将右侧触摸到面板的边框?

您需要设置RelativePanel.RightOf="PageTitle"RelativePanel.AlignVerticalCenterWith="PageTitle"

<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,0,0,0">
        <TextBlock x:Name="PageTitle"
           RelativePanel.AlignTopWithPanel="True"
           Style="{StaticResource TitleTextBlockStyle}" VerticalAlignment="Center" FontSize="35">This is my page title</TextBlock>
        <TextBlock x:Name="ActivityLabel"
           RelativePanel.Below="PageTitle"
           Style="{StaticResource CaptionTextBlockStyle}">Activity</TextBlock>
        <ComboBox x:Name="ActivityOptions"
          RelativePanel.RightOf="PageTitle"
          RelativePanel.AlignRightWithPanel="True"
          RelativePanel.AlignVerticalCenterWith="PageTitle"
          ItemsSource="{Binding Path=SupportedActivityTypes}">
        </ComboBox>
</RelativePanel>

enter image description here