C# 在Windows 8应用程序中扩展启动后无法导航到页面

C# 在Windows 8应用程序中扩展启动后无法导航到页面,c#,xaml,windows-runtime,winrt-xaml,async-await,C#,Xaml,Windows Runtime,Winrt Xaml,Async Await,我已经按照微软提供的指南创建了扩展的启动屏幕。屏幕显示,数据加载,但随后应用程序无法导航到登录页。这怎么可能 ExtendedSplash.xaml.cs public sealed partial class ExtendedSplash { public ExtendedSplash(SplashScreen splash) { this.InitializeComponent(); // Position the extended spl

我已经按照微软提供的指南创建了扩展的启动屏幕。屏幕显示,数据加载,但随后应用程序无法导航到登录页。这怎么可能

ExtendedSplash.xaml.cs

public sealed partial class ExtendedSplash
{

    public ExtendedSplash(SplashScreen splash)
    {
        this.InitializeComponent();

        // Position the extended splash screen image in the same location as the splash screen image.
        this.extendedSplashImage.SetValue(Canvas.LeftProperty, splash.ImageLocation.X);
        this.extendedSplashImage.SetValue(Canvas.TopProperty, splash.ImageLocation.Y);
        this.extendedSplashImage.Height = splash.ImageLocation.Height;
        this.extendedSplashImage.Width = splash.ImageLocation.Width;

        // Position the extended splash screen's progress ring.
        this.ProgressRing.SetValue(Canvas.TopProperty, splash.ImageLocation.Y + splash.ImageLocation.Height + 32);
        this.ProgressRing.SetValue(Canvas.LeftProperty,
     splash.ImageLocation.X +
             (splash.ImageLocation.Width / 2) - 15);
    }

    public void onSplashScreenDismissed(SplashScreen sender, object args)
    {

    }
}
来自App.xaml.cs

    protected override async void OnLaunched(LaunchActivatedEventArgs args)
    {
        _newsDataSource = (NewsDataSource)App.Current.Resources["newsDataSource"];
        _movieDataSource = (MovieDataSource)App.Current.Resources["moviesDataSource"];
        await PerformDataFetch();

        // extended splash screen loading
        ExtendedSplash eSplash = new ExtendedSplash(args.SplashScreen);
        args.SplashScreen.Dismissed +=
            new TypedEventHandler<SplashScreen, object>(eSplash.onSplashScreenDismissed);

        // Place the frame in the current Window
        Window.Current.Content = eSplash;
        Window.Current.Activate();
    }

    internal async Task PerformDataFetch()
    {
        // load news
        if (_newsDataSource != null)
        {
            if (!_newsDataSource.News.Any())
            {
                await _newsDataSource.GetNewsAsync();
            }
        }

        // load movies
        if (_movieDataSource != null)
        {
            if (!_movieDataSource.Movies.Any())
            {
                await _movieDataSource.GetMoviesAsync();
            }
        }

        RemoveExtendedSplash();
    }

    internal void RemoveExtendedSplash()
    {
        Window.Current.Content = new MainPage();
        Window.Current.Activate();
    }
protectedoverride async void OnLaunched(启动ActivatedEventargs args)
{
_newsDataSource=(newsDataSource)App.Current.Resources[“newsDataSource”];
_movieDataSource=(movieDataSource)App.Current.Resources[“movieDataSource”];
等待PerformDataFetch();
//扩展启动屏幕加载
ExtendedSplash eSplash=新的ExtendedSplash(args.SplashScreen);
args.SplashScreen+=
新型Deventhandler(eSplash.onSplashScreenDismissed);
//将框架放置在当前窗口中
Window.Current.Content=eSplash;
Window.Current.Activate();
}
内部异步任务PerformDataFetch()
{
//加载新闻
if(_newsDataSource!=null)
{
if(!\u newsDataSource.News.Any())
{
wait_newsDataSource.GetNewsAsync();
}
}
//加载电影
if(_movieDataSource!=null)
{
if(!\u movieDataSource.Movies.Any())
{
wait_movieDataSource.GetMoviesAsync();
}
}
RemoveExtendedSplash();
}
内部空隙清除扩展板()
{
Window.Current.Content=新主页();
Window.Current.Activate();
}

如果在最后一个方法上放置断点,则会激发,但不会转换到页面。我喜欢ProgressRing的动画,但该应用程序也应该做些别的事情:)

ExtendedSplash必须是一个页面。因此扩展了splash.xaml.cs:

public sealed partial class ExtendedSplash : Page
{
    public ExtendedSplash()
    {
        this.InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        SplashScreen splash = (SplashScreen) e.Parameter;

        // Position the extended splash screen image in the same location as the splash screen image.
        this.extendedSplashImage.SetValue(Canvas.LeftProperty, splash.ImageLocation.X);
        this.extendedSplashImage.SetValue(Canvas.TopProperty, splash.ImageLocation.Y);
        this.extendedSplashImage.Height = splash.ImageLocation.Height;
        this.extendedSplashImage.Width = splash.ImageLocation.Width;

        // Position the extended splash screen's progress ring.
        this.ProgressRing.SetValue(Canvas.TopProperty, splash.ImageLocation.Y + splash.ImageLocation.Height + 32);
        this.ProgressRing.SetValue(Canvas.LeftProperty,
     splash.ImageLocation.X +
             (splash.ImageLocation.Width / 2) - 15);
    }
}
所有数据提取操作都应在App.xaml.cs中执行。完成后,只需将框架导航到登录页就足够了

sealed partial class App : Application
{
    private Frame _rootFrame;

    protected override async void OnLaunched(LaunchActivatedEventArgs args)
    {
        if(_rootFrame == null)
            _rootFrame = new Frame();

        // Place the frame in the current Window
        _rootFrame.Navigate(typeof (ExtendedSplash), args.SplashScreen);
        Window.Current.Content = _rootFrame;
        Window.Current.Activate();

        await PerformDataFetch();
    }

    internal async Task PerformDataFetch()
    {
        // data loading here

        RemoveExtendedSplash();
    }

    internal void RemoveExtendedSplash()
    {
        if (_rootFrame != null) _rootFrame.Navigate(typeof (MainPage));
    }
}

能否尝试将Window.Current.Content最初设置为一个框架,然后让它最初导航到ExtendedSplashScreen,然后再导航到MainPage?是的,如果我将ExtendedSplash视为页面,它会工作:)谢谢!