无法在Windows 8应用扩展飞溅后,导航到页面(Unable to navigate to pa

2019-09-22 20:59发布

我创建了继微软提供指南扩展启动画面。 屏幕显示关闭,数据加载,但随后的应用程序不导航到登陆页面。 这怎么可能?

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();
    }

如果把一个断点在最后一个方法,它触发,但页面没有过渡。 我喜欢ProgressRing的动画,但应用程序应该做其他事情:)

Answer 1:

ExtendedSplash必须是一个页面。 所以ExtendedSplash.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));
    }
}


文章来源: Unable to navigate to page after extended splash in Windows 8 application