繁体   English   中英

WebView未在Pivot,C#UWP中显示

[英]WebView not showing in Pivot, C# UWP

我在带有3个选项卡的Grid有一个Pivot ,但是当我为我的2个WebView运行应用程序时,URL的源未显示(第3个尚未配置)。 当我从Pivot取出WebView并将其仅放入Grid ,它显示得很好。

我的xaml文件:

<Page
    x:Class="Study_Bot.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Study_Bot"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="1270">
        <Pivot x:Name="rootPivot" Title="" Margin="0,312,0,0" HorizontalAlignment="Center" VerticalAlignment="Top" Height="388" Width="1138">
            <Pivot.RightHeader>
                <CommandBar ClosedDisplayMode="Compact">
                    <AppBarButton Icon="Back" Label="Previous" Click="BackButton_Click"/>
                    <AppBarButton Icon="Forward" Label="Next" Click="NextButton_Click"/>
                </CommandBar>
            </Pivot.RightHeader>
            <PivotItem Header="Encyclopedia">
                <!--Pivot content goes here-->
                <WebView x:Name="encyclopedia" Source="https://www.britannica.com/search?query=virus" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
            </PivotItem>
            <PivotItem Header="Journals">
                <!--Pivot content goes here-->
                <WebView x:Name="journals" Source="http://search.sciencemag.org/?searchTerm=virus&amp;order=tfidf&amp;limit=textFields&amp;pageSize=10&amp;&amp;" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
            </PivotItem>
            <PivotItem Header="News / Blogs">
                <!--Pivot content goes here-->
                <WebView x:Name="newsBlogs"  />
            </PivotItem>
        </Pivot>

    </Grid>
</Page>

我的xaml.cs文件:

namespace Study_Bot
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void BackButton_Click(object sender, RoutedEventArgs e)
        {
            if (rootPivot.SelectedIndex > 0)
            {
                // If not at the first item, go back to the previous one.
                rootPivot.SelectedIndex -= 1;
            }
            else
            {
                // The first PivotItem is selected, so loop around to the last item.
                rootPivot.SelectedIndex = rootPivot.Items.Count - 1;
            }
        }

        private void NextButton_Click(object sender, RoutedEventArgs e)
        {
            if (rootPivot.SelectedIndex < rootPivot.Items.Count - 1)
            {
                // If not at the last item, go to the next one.
                rootPivot.SelectedIndex += 1;
            }
            else
            {
                // The last PivotItem is selected, so loop around to the first item.
                rootPivot.SelectedIndex = 0;
            }
        }

    }
}

我不了解何时固定枢轴的高度和宽度,所以为什么要对齐其中心或顶部,因为它已经根据边距捕获了网格,并且如果您不在网格内拉伸其垂直和水平对齐,这将需要最多只能为内部元素定义的空间和webview的高度宽度不是固定的。

<Pivot x:Name="rootPivot" Title="" Margin="0,312,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="388" Width="1138">

全部或替代删除水平和垂直对齐方式。

*注意:在您的应用中,放置边距,高度和宽度的方式会导致与屏幕尺寸和自适应性有关的问题,总之,您的应用元素不会根据屏幕尺寸进行调整或调整大小,例如PC,平板电脑或移动设备

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM