2013-10-29 300 views
0

我想讓SplashScreenService啓動並運行。它確實顯示我的飛濺屏幕,但它不會關閉,永遠不會。SplashScreenService不起作用,因爲我想

我有這樣的代碼在app.xaml.cs:

protected override void OnStartup(StartupEventArgs e) 

{ 

ServiceLocator.Default.RegisterTypeIfNotYetRegistered<ISplashScreenService, SplashScreenService>(); 

var splashScreenService = ServiceLocator.Default.ResolveType<ISplashScreenService>(); 
      splashScreenService.Enqueue(new ActionTask("Task1", tracker => Thread.Sleep(2000))); 

splashScreenService.Commit<SplashScreenViewModel>(); 

base.OnStartup(e); 

} 

任何人可以幫助我什麼,我做錯了什麼?

回答

1

好像你正在阻塞UI線程,請嘗試用這種方式:

public partial class App 
{ 
    #region Methods 

    protected override void OnStartup(StartupEventArgs e) 
    { 
     base.OnStartup(e); 
     var splashScreenService = ServiceLocator.Default.ResolveType<ISplashScreenService>(); 
     splashScreenService.Enqueue(new ActionTask("Task1", tracker => Thread.Sleep(2000))); 
     splashScreenService.Enqueue(new ActionTask("Task2", tracker => Thread.Sleep(2000))); 
     splashScreenService.Enqueue(new ActionTask("Task3", tracker => Thread.Sleep(2000))); 
     splashScreenService.CommitAsync(); 
    } 

    #endregion 
} 

或自定義開機畫面

public partial class App 
{ 
    #region Methods 

    protected override void OnStartup(StartupEventArgs e) 
    { 
     base.OnStartup(e); 
     var splashScreenService = ServiceLocator.Default.ResolveType<ISplashScreenService>(); 
     splashScreenService.Enqueue(new ActionTask("Task1", tracker => Thread.Sleep(2000))); 
     splashScreenService.Enqueue(new ActionTask("Task2", tracker => Thread.Sleep(2000))); 
     splashScreenService.Enqueue(new ActionTask("Task3", tracker => Thread.Sleep(2000))); 
     splashScreenService.CommitAsync<SplashScreenViewModel>(); 
    } 

    #endregion 
} 
+0

感謝,例如1確實會導致異常:無法設置Owner屬性到以前未顯示的窗口。 示例2簡要顯示了初始屏幕和第二個主屏幕。幾秒鐘後,閃屏和主屏幕自動關閉。 我正在尋找一個解決方案來顯示splashscreen,做一些初始化的東西,初始化後我想加載主屏幕,當主屏幕加載時,關閉splashscreen。 這可能嗎? – user2932373

+0

對於我使用3.7穩定版本的例子。對的,這是可能的。此功能涵蓋了這種情況。 –

相關問題