WebView未在Pivot,C#UWP中显示

时间:2018-07-27 17:49:36

标签: c# xaml uwp

我在一个带有三个标签的Pivot中有一个Grid,但是当我为自己的WebView中的两个运行应用程序时,URL的来源没有显示(第三个尚未配置)。当我从WebView中取出Pivot并将其仅放入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;
            }
        }

    }
}

1 个答案:

答案 0 :(得分:1)

我不知道您何时固定枢轴的高度和宽度,为什么要对齐轴的中心或顶部,因为它已经根据边距捕获了网格,并且如果您不在网格内垂直和水平对齐,这只会占用内部元素定义的空间,并且webview的高度宽度不是固定的。

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

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

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