UWP, C#, XAMLでアプリを開発中のものです。
広告が準備されるまでスプラッシュスクリーンの表示をしたいと思っています。(スプラッシュスクリーンから遷移したときには広告が確実に表示される状態)
広告はAdvertisingPage.Xamlを用意し、MainPage.Xaml(スプラッシュスクリーンから遷移)に設定したSplitViewのFrameオブジェクトから遷移するようにしています。
広告のFilledイベントを処理してみたのですが、うまくいきません。
追加スプラッシュスクリーンのコードは以下のようになります。
C#
1//追加スプラッシュ画面に関するクラス 2 partial class ExtendedSplash : Page 3 { 4 internal Rect splashImageRect; //画像の座標を格納 5 SplashScreen splash; //SplashScreenオブジェクトを格納する変数 6 internal bool dismissed = false; //表示されたスプラッシュ画面が閉じられたかどうかを追跡する変数 7 internal Frame rootFrame; 8 9 public ExtendedSplash(SplashScreen splashscreen, bool loadState) 10 { 11 InitializeComponent(); 12 13 //Windowのサイズ変更イベントハンドラー 14 Window.Current.SizeChanged += new WindowSizeChangedEventHandler(ExtendedSplashOnResize); 15 16 splash = splashscreen; 17 18 if (splash != null) 19 { 20 // 21 splash.Dismissed += new TypedEventHandler<SplashScreen, Object>(DismissedEventHandler); 22 23 // 24 splashImageRect = splash.ImageLocation; 25 PositionImage(); 26 27 // 28 PositionRing(); 29 } 30 31 //フレームの生成 32 rootFrame = new Frame(); 33 34 RestoreStateAsync(loadState); 35 } 36 37 38 void RestoreStateAsync(bool loadState) 39 { 40 if (loadState) 41 { 42 //Listの確保 43 var app = Application.Current as App; 44 45 app.sketchBook = new List<Canvas>(); 46 app.brushColorsArray = new List<List<Color>>(); 47 48 //データロード 49 app.DataLoad(); 50 } 51 } 52 53 void DismissedEventHandler(SplashScreen sender, object args) 54 { 55 dismissed = true; 56 } 57 58 internal void DismissExtendedSplash() 59 { 60 var app = Application.Current as App; 61 62 if (app.Option == true) 63 rootFrame.Navigate(typeof(MainPage), app.sketchBook); 64 else 65 rootFrame.Navigate(typeof(MainPage)); 66 67 Window.Current.Content = rootFrame; 68 } 69 70 void ExtendedSplashOnResize(object sender, WindowSizeChangedEventArgs args) 71 { 72 if (splash != null) 73 { 74 //アップデート 75 splashImageRect = splash.ImageLocation; 76 PositionImage(); 77 PositionRing(); 78 } 79 } 80 81 void PositionRing() 82 { 83 //イメージの 32 ピクセル下の中央に配置する 84 SplashProgressRing.SetValue(Canvas.LeftProperty, splashImageRect.X + (splashImageRect.Width * 0.5) - (SplashProgressRing.Width * 0.5)); 85 SplashProgressRing.SetValue(Canvas.TopProperty, (splashImageRect.Y + splashImageRect.Height + splashImageRect.Height * 0.1)); 86 } 87 88 void PositionImage() 89 { 90 ExtendedSplashImage.SetValue(Canvas.LeftProperty, splashImageRect.X); 91 ExtendedSplashImage.SetValue(Canvas.TopProperty, splashImageRect.Y); 92 ExtendedSplashImage.Height = splashImageRect.Height; 93 ExtendedSplashImage.Width = splashImageRect.Width; 94 } 95 }
何かよい実装方法はないでしょうか?
コードで示してもらえるとありがたいです。
このイベントやプロパティを使ってみたらみたいなヒントでも構いません。
よろしくお願いします。
追記
Filledイベントでフラグをtrueに設定し、app.xaml.cs内でそのフラグがtrueになるまで無限ループを回しています。しかし、広告が取得できてないのか、そもそも広告ページにナビゲートしないとFilledイベントが発生しないのかがわかりません。
またデバッグすると無限ループから脱出できていません。
app.xaml.csのOnLaunched()は以下の通りです。
C#
1protected override void OnLaunched(LaunchActivatedEventArgs e) 2 { 3 4#if DEBUG 5 if (System.Diagnostics.Debugger.IsAttached) 6 { 7 this.DebugSettings.EnableFrameRateCounter = true; 8 } 9#endif 10 11 adPage = new AdvertisingPage(); 12 13 //PC 14 if (!Commons.DeviceManager.isMobile) 15 ChangeTitleBarColor(); 16 17 Frame rootFrame = Window.Current.Content as Frame; 18 19 //ウィンドウに既にコンテンツが表示されている場合は、アプリケーションの初期化を繰り返さずに、 20 //ウィンドウがアクティブであることだけを確認してください 21 if (rootFrame == null) 22 { 23 //ナビゲーションコンテキストとして動作するフレームを作成し、最初のページに移動します 24 rootFrame = new Frame(); 25 26 if ((e.PreviousExecutionState != ApplicationExecutionState.Running)) 27 { 28 bool loadState = (e.PreviousExecutionState == ApplicationExecutionState.Terminated); 29 ExtendedSplash extendedSplash = new ExtendedSplash(e.SplashScreen, loadState); 30 rootFrame.Content = extendedSplash; 31 Window.Current.Content = rootFrame; 32 do { } while (!adPage.adFlag); 33 extendedSplash.DismissExtendedSplash(); 34 } 35 } 36 37 if (rootFrame.Content == null) 38 { 39 //rootFrame.Navigate(typeof(MainPage), e.Arguments); 40 rootFrame.Navigate(typeof(MainPage)); 41 } 42 //現在のウィンドウがアクティブであることを確認します 43 Window.Current.Activate(); 44 }
回答1件
あなたの回答
tips
プレビュー