在通用Windows平台上导航

时间:2016-04-12 08:36:53

标签: webview navigation windows-10-universal

我正在开发一个使用webview托管Web应用程序的Windows Universal App。 按照步骤进行。

  1. 创建空白通用窗口应用。创建启动画面。组 启动画面作为起始页面。在我想做的所有活动之后 导航具有Web视图控件的主页面。
  2. 将网址示例“http:www.google.come”设置为网络视图的来源。一切都很好,但主页需要时间,我希望看到相同的启动画面,直到它加载。
  3. 我正在使用的导航代码  this.Frame.Navigate(typeof运算(的MainPage));
  4. 完整源代码

    public sealed partial class ExtentedSpash : Page
    {
        public ProgressMessage Progress;
        public ExtentedSpash()
        {
            this.InitializeComponent();
            Progress = ProgressMessage.GetMessage();
            DataContext = Progress;
            Window.Current.Activate();
            Loaded += Splash_Loaded;
        }
    
        private async void Splash_Loaded(object sender, RoutedEventArgs e)
        {
            await Initialize();
            Window.Current.Activate();
    
            await ClearBrowserCache();
            Window.Current.Activate();
    
            //Task.WaitAll(TaskList.ToArray());
            await StartApplication();
        }
    
    
        public async Task Initialize()
        {
            Progress.ActionMessage = "Initialize the controls";
            await Task.Delay(TimeSpan.FromSeconds(10));
        }
        public async Task ClearBrowserCache()
        {
            Progress.ActionMessage = "Clear Browser Cache";
            await Task.Delay(TimeSpan.FromSeconds(10));
        }
    
        public async Task StartApplication()
        {
            Progress.ActionMessage = "Loading";
            await Task.Delay(TimeSpan.FromSeconds(10));
            this.Frame.Navigate(typeof(MainPage));
        }
    
        private void btnMain_Click(object sender, RoutedEventArgs e)
        {
    
        }
    }
    public class ProgressMessage : INotifyPropertyChanged
    {
        private string statusMessage;
    
        public string StatusMessage
        {
            get { return statusMessage; }
    
            set
            {
                statusMessage = value;
                RaiseProperChanged();
            }
        }
    
        private string actionMessage;
    
        public string ActionMessage
        {
            get { return actionMessage; }
    
            set
            {
                actionMessage = value;  
                RaiseProperChanged();
            }
        }
        private bool showProgress;
    
        public bool ShowProgress
        {
            get { return showProgress; }
            set { showProgress = value;
                RaiseProperChanged();
            }
        }
    
    
        public static ProgressMessage GetMessage()
        {
    
            var msg = new ProgressMessage()
            {
                StatusMessage = "Initializing Application",
                ActionMessage = "One moment please...",
                showProgress = true
            };
    
            return msg;
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void RaiseProperChanged(
           [CallerMemberName] string caller = "")
        {
    
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(caller));
            }
    
        }
    
    
    }
    

    }

    我希望“On Loading”消息应该显示直到它完全加载应用程序。

1 个答案:

答案 0 :(得分:1)

正如我们已经讨论的那样,如果您只想覆盖WebView来源未完全加载,您可以这样做:

<Page.Resources>
    <Storyboard x:Key="MyTextSTD" x:Name="MyTextSTD" RepeatBehavior="Forever">
        <ColorAnimationUsingKeyFrames Storyboard.TargetName="tbbrush" Storyboard.TargetProperty="Color" Duration="0:0:10">
            <DiscreteColorKeyFrame KeyTime="0:0:0" Value="Red" />
            <LinearColorKeyFrame KeyTime="0:0:5" Value="Blue" />
            <LinearColorKeyFrame KeyTime="0:0:10" Value="Purple" />
        </ColorAnimationUsingKeyFrames>
    </Storyboard>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <WebView Source="https://msdn.microsoft.com/library/windows/apps/xaml/mt244352.aspx" NavigationCompleted="WebView_NavigationCompleted">
    </WebView>
    <Grid x:Name="loadingGrid" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Visibility="Visible">
        <TextBlock Text="On Loading..." FontSize="50" VerticalAlignment="Center" HorizontalAlignment="Center">
            <TextBlock.Foreground>
                <SolidColorBrush x:Name="tbbrush" />
            </TextBlock.Foreground>
        </TextBlock>
    </Grid>
</Grid>

代码背后:

public MainPage()
{
    this.InitializeComponent();
    MyTextSTD.Begin();
}

private void WebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
    loadingGrid.Visibility = Visibility.Collapsed;
}

这很简单,我使用TextBlock和一些颜色动画来显示消息。当WebView的来源完全加载时,此消息将消失。