积极答复者
metro进度控制(progress)如何在主页面载入前加载,页面载入后消失

问题
答案
-
我自己的项目中写过一个启动器,你们看一下,通过延迟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
- 已标记为答案 Jie BaoModerator 2012年9月24日 6:53
全部回复
-
我自己的项目中写过一个启动器,你们看一下,通过延迟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
- 已标记为答案 Jie BaoModerator 2012年9月24日 6:53