none
metro进度控制(progress)如何在主页面载入前加载,页面载入后消失 RRS feed

答案

  • 我自己的项目中写过一个启动器,你们看一下,通过延迟Splash 页面,让服务在其中启动,并且可以显示进度条:

    Bootstrapper类

    public class Bootstrapper { private Frame rootFrame; private LaunchActivatedEventArgs launchArgs; private Bootstrapper() { } private static Bootstrapper _currentInstance; public static Bootstrapper CurrentBootstrapper { get { if (_currentInstance == null) _currentInstance = new Bootstrapper(); return _currentInstance; } } public void Run(LaunchActivatedEventArgs args) { launchArgs = args; if (Window.Current.Content == null) { rootFrame = new Frame(); rootFrame.Navigate(typeof(Splash), args.SplashScreen); Window.Current.Content = rootFrame; } Window.Current.Activate(); } public async Task Suspending() { await SuspensionManager.SaveAsync(); } #region Initialize Data private IAsyncAction InitializeConfigAsync() { return AsyncInfo.Run(async token => { try { ... } catch (Exception ex) { ... } }); } #endregion public async void Initialize() { await InitializeLogger(); await InitializeConfigAsync(); await rootFrame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { if (launchArgs.PreviousExecutionState == ApplicationExecutionState.Running) { CoreApplication.Properties.Clear(); Window.Current.Activate(); return; } rootFrame = new Frame(); SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); if (launchArgs.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException ex) { ex.WriteLog(); } } if (rootFrame.Content == null) { if (!rootFrame.Navigate(typeof(ServiceChannelItemsPage))) { throw new Exception("Failed to create initial page"); } } Window.Current.Content = rootFrame; }); } }

    在这个启动器类中,我们可以实现一些异步方法,比如我这里的InitializeConfigAsync,然后先调用他去加载你的服务,数据,然后最后通过Frame导航到你的主页面。

    具体如何结合 App.xaml和Splash.xaml, 看下我的完整例子:https://skydrive.live.com/#cid=51B2FDD068799D15&id=51B2FDD068799D15%211108 (例子中我简单的 await Task.Delay(5000);  等待了5秒载入主页面


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    2012年9月19日 3:26
    版主

全部回复

  • 您好,

    您可以控制ProgressBar的Visibility屬性,設定成Collapsed就會消失

    2012年9月18日 15:45
  • 楼主应该不是这个意思,他应该是想问 如何在启动页面中放置一个进度条,能显示主程序的启动进度问题? 

    我也想了解,在有些主程序启动较长时,为了不让用户以为程序假死,可以在启动页面中,添加那种 。。。。不断来回,提示用户程序正在启动的效果,如何实现?

    2012年9月19日 3:03
  • 我自己的项目中写过一个启动器,你们看一下,通过延迟Splash 页面,让服务在其中启动,并且可以显示进度条:

    Bootstrapper类

    public class Bootstrapper { private Frame rootFrame; private LaunchActivatedEventArgs launchArgs; private Bootstrapper() { } private static Bootstrapper _currentInstance; public static Bootstrapper CurrentBootstrapper { get { if (_currentInstance == null) _currentInstance = new Bootstrapper(); return _currentInstance; } } public void Run(LaunchActivatedEventArgs args) { launchArgs = args; if (Window.Current.Content == null) { rootFrame = new Frame(); rootFrame.Navigate(typeof(Splash), args.SplashScreen); Window.Current.Content = rootFrame; } Window.Current.Activate(); } public async Task Suspending() { await SuspensionManager.SaveAsync(); } #region Initialize Data private IAsyncAction InitializeConfigAsync() { return AsyncInfo.Run(async token => { try { ... } catch (Exception ex) { ... } }); } #endregion public async void Initialize() { await InitializeLogger(); await InitializeConfigAsync(); await rootFrame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { if (launchArgs.PreviousExecutionState == ApplicationExecutionState.Running) { CoreApplication.Properties.Clear(); Window.Current.Activate(); return; } rootFrame = new Frame(); SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); if (launchArgs.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException ex) { ex.WriteLog(); } } if (rootFrame.Content == null) { if (!rootFrame.Navigate(typeof(ServiceChannelItemsPage))) { throw new Exception("Failed to create initial page"); } } Window.Current.Content = rootFrame; }); } }

    在这个启动器类中,我们可以实现一些异步方法,比如我这里的InitializeConfigAsync,然后先调用他去加载你的服务,数据,然后最后通过Frame导航到你的主页面。

    具体如何结合 App.xaml和Splash.xaml, 看下我的完整例子:https://skydrive.live.com/#cid=51B2FDD068799D15&id=51B2FDD068799D15%211108 (例子中我简单的 await Task.Delay(5000);  等待了5秒载入主页面


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    2012年9月19日 3:26
    版主