WPFでスプラッシュスクリーンを作成しました。
このサイトを参考にして下のようなコードをかきました。
public partial class App { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); //initialize the splash screen and set it as the application main window var splashScreen = new SplashScreenWindow(); this.MainWindow = splashScreen; splashScreen.Show(); //in order to ensure the UI stays responsive, we need to //do the work on a different thread Task.Factory.StartNew(() => { //simulate some work being done System.Threading.Thread.Sleep(3000); //since we're not on the UI thread //once we're done we need to use the Dispatcher //to create and show the main window this.Dispatcher.Invoke(() => { //initialize the main window, set it as the application main window //and close the splash screen var mainWindow = new MainWindow(); this.MainWindow = mainWindow; mainWindow.Show(); splashScreen.Close(); }); }); } }
MainwindowにはListViewが存在しています。
ListViewの選択されたアイテムが変わった際のイベントハンドラに下のようにNavigationServiceを利用したページ遷移をおこなっています。
上記のスプラッシュスクリーンを作成してからこのページ遷移時に**親の Freezable とは異なるスレッドに属する DependencyObject を使用することはできません。**とゆうエラーが発生します。
色々調べてみましたが、自己解決できそうにありませんので有識者の方いましたら原因と解決策をご教示ください。
Frame.NavigationService.Navigate(new HomePage());
回答1件
あなたの回答
tips
プレビュー