WPF app call UWP app to show Ads RRS feed

  • Question

  • We have a WPF App, and has published it to the Microsoft App store using Desktop App Converter. Lately, we try to add Microsoft Interstitial ads in the App.
    But now, Microsoft Interstitial ads only support in the UWP project. So, we add new UWP ads project in our exist WPF project and this UWP project only to show the Interstitial ads.
    The existing WPF project will launch this UWP ads project when need to show the ads.
    it works well with appxbundle test package, that was built with vs2017, and the Ads could be shown normally. When publish the appxupload package to the Microsoft store, and after download/install the app from the store, the ads UWP App could be launched by the WPF App but failed to get the Interstitial ads.
    My questions are:
      1. And does this solution supported by the Microsoft?
      2. why it works well with test package but failed with the official installation from the Microsoft App Store?

    The following is the detail steps I have done for this:
    1. Let the WPF App could launch the UWP ads App.
      1.1 Add new UWPAdsApp project in the existing App Solution.
      1.2 Add "windows.protocol", showuwpads, in the Package.appxmainifest
            <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
                <uap:Extension Category="windows.protocol" Executable="UWPAdsApp.exe" EntryPoint="UWPAdsApp.App">
                  <uap:Protocol Name="showuwpads" />
      1.3 In the WPF App side, add function to launch the UWP Ads App, and call this function if need to show ads.
          public async static void ShowAds()
              string str = "showuwpads://";
              Uri uri = new Uri(str);
              var success = await Windows.System.Launcher.LaunchUriAsync(uri);
              if (success == true)
      1.4 In the UWP App side, override the OnActivated function to activate the UWP App via the Protocol. (Added in the App.xaml.cs)
            protected override void OnActivated(IActivatedEventArgs args)
                switch (args.Kind)
                    case ActivationKind.Protocol:
                        ProtocolActivatedEventArgs protocolArgs = (ProtocolActivatedEventArgs)args;
                        Uri uri = protocolArgs.Uri;
                        if (uri.Scheme == "showuwpads")
                            Frame rootFrame = Window.Current.Content as Frame;
                            if (rootFrame == null)
                                rootFrame = new Frame();
                                Window.Current.Content = rootFrame;
                            //Request the Microsoft Interstitial Ads here

    2. Request and show the ads in UWP App.
      2.1 Add functions to handle the ads in the UWP App.

          InterstitialAd adInterBanner = new InterstitialAd();
          private void RequestAds()
              adInterBanner.ErrorOccurred += OnAdError;
              adInterBanner.AdReady += OnAdReady;
              adInterBanner.Cancelled += OnAdCancelled;
              adInterBanner.Completed += OnAdCompleted;
              adInterBanner.RequestAd(AdType.Display, "d25517cb-12d4-4699-8bdc-52040c712cab", "test");
          private void OnAdReady(object sender, object e)
              InterstitialAd ad = (InterstitialAd)sender;
              if (ad == adInterBanner)
          // This is an event handler for the interstitial ad. It is triggered when the interstitial ad is cancelled.
          private void OnAdCancelled(object sender, object e)
          // This is an event handler for the interstitial ad. It is triggered when the interstitial ad has completed playback.
          private void OnAdCompleted(object sender, object e)
          // This is an error handler for the interstitial ad.
          private void OnAdError(object sender, Microsoft.Advertising.WinRT.UI.AdErrorEventArgs e)
    Sunday, September 22, 2019 12:53 PM

All replies

  • Did you solve your problem?

    If not try using XAML Island instead of separate UWP app 

    Make the community better together

    Wednesday, October 16, 2019 8:07 AM