Skip to main content
 首页 » 编程设计

c#之RelativePanel 中的 UWP WebView 不显示网页

2024年02月27日32cmt

我在 RelativePanel 内的 PivotItem 中有 3 个 WebView,如下所示:

<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
 
    <Pivot Name="pivot" 
           RelativePanel.AlignTopWithPanel="True" 
           RelativePanel.AlignLeftWithPanel="True" 
           RelativePanel.AlignRightWithPanel="True"> 
        <PivotItem Header="Slack LiveTile"> 
            <WebView Name="webView_001" /> 
        </PivotItem> 
        <PivotItem Header="Slack RDV Tech"> 
            <WebView Name="webView_002" /> 
        </PivotItem> 
        <PivotItem Header="WhatsApp"> 
            <WebView Name="webView_003" /> 
        </PivotItem> 
    </Pivot> 
 
    <CommandBar 
        RelativePanel.AlignBottomWithPanel="True" 
        RelativePanel.AlignLeftWithPanel="True" 
        RelativePanel.AlignRightWithPanel="True" /> 
 
</RelativePanel> 

我的问题是 WebView 内容没有显示,我不明白为什么。在使用 RelativePanel 之前,我使用了 Grid 并且效果很好。

你能解释一下为什么它不起作用吗?

感谢您的帮助。

请您参考如下方法:

这是因为您还需要 Pivot 上的 RelativePanel.AlignBottomWithPanel="True" 来拉伸(stretch)以填充整个空间,否则它只会占用足够的空间PivotHeader。