如何使用xaml RelativePanel创建两列布局?

时间:2017-06-30 12:29:29

标签: xaml uwp relativelayout uwp-xaml relativepanel

我真的很想在我写的UWP应用中使用RelativePanel来简化视觉状态。

这就是我想要的

enter image description here

我已尝试使用以下XAML实现此目的:

<RelativePanel>

    <TextBlock x:Name="Title" Height="50" Margin="15" FontSize="24"
        RelativePanel.AlignTopWithPanel="True" 
        RelativePanel.AlignLeftWithPanel="True" 
        RelativePanel.AlignRightWithPanel="True">
    </TextBlock>

    <TextBox x:Name="Editor" Margin="15" Padding="20" HorizontalAlignment="Stretch" 
        RelativePanel.AlignLeftWithPanel="True" 
        RelativePanel.Below="Title" 
        RelativePanel.RightOf="FileList">
    </TextBox>  

    <ListView x:Name="FileList" HorizontalAlignment="Stretch" Margin="15"
        RelativePanel.AlignRightWithPanel="True" 
        RelativePanel.Below="Title">
    </ListView>

</RelativePanel>

这不起作用。 Editor不伸展。如果我将Editor设置为RelativePanel.AlignRightWith="FilesList",它会延伸过去的文件列表并填充窗口。

有没有办法用RelativePanel做我想做的事情?请不要在Grid中发布有关如何执行此操作的建议,我已经可以这样做了 - 我想在这种情况下使用RelativePanel

1 个答案:

答案 0 :(得分:1)

您的Editor控件应该有 -

RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below="Title"
RelativePanel.LeftOf="FileList"
RelativePanel.AlignBottomWithPanel="True"

请注意,它应该是LeftOf,而不是RightOf。您还需要将AlignBottomWithPanel设置为True