2

使用 webview.navigate(url) 时,整个应用程序冻结。这在 x86 芯片上很明显,但它完全冻结了平板电脑近 50 秒。

我已经尝试了很多东西来尝试编组线程,但绝对没有什么能让它变得更好。

有什么建议吗?

这是xaml和c#

<Page
    x:Class="WebviewSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WebviewSample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0">
            <ListView x:Name="listView" ItemsSource="{Binding}" SelectionChanged="ListView_OnSelectionChanged">

            </ListView>
        </Grid>
        <Grid Grid.Column="1">
            <WebView x:Name="webView"></WebView>
        </Grid>
    </Grid>
</Page>



using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace WebviewSample
{
    /// <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();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var itemsList = new List<ListViewItem>();
            for (var i = 0; i < 300; i++)
            {
                var listViewItem = new ListViewItem {Content = "Click Me!"};
                itemsList.Add(listViewItem);
            }
            listView.DataContext = itemsList;
        }

        private void ListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            webView.Navigate(new Uri("http://online.wsj.com/article/SB10001424127887324299104578529112289298922"));
        }
    }
}
4

0 回答 0