Last active
July 3, 2017 04:07
-
-
Save jamesmontemagno/bb280f3e982b68ce2e2baca1bbcd9baf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using Xamarin.Forms; | |
| using Xamarin.Forms.Platform.UWP; | |
| using System.Linq; | |
| using System.Threading.Tasks; | |
| using Microsoft.Advertising.Ads; | |
| using Microsoft.Advertising.WinRT.UI; | |
| using Windows.System.Profile; | |
| [assembly: ExportRenderer(typeof(PluginsForXamarin.Controls.AdControlView), typeof(PluginsForXamarin.UWP.PlatformSpecific.AdViewRenderer))] | |
| namespace PluginsForXamarin.UWP.PlatformSpecific | |
| { | |
| public class AdViewRenderer : ViewRenderer<Controls.AdControlView, AdControl> | |
| { | |
| string bannerId = "test"; | |
| AdControl adView; | |
| string applicationID = "3f83fe91-d6be-434d-a0ae-7351c5a997f1"; | |
| void CreateNativeAdControl() | |
| { | |
| if (adView != null) | |
| return; | |
| var width = 300; | |
| var height = 50; | |
| if(AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Desktop") | |
| { | |
| width = 728; | |
| height = 90; | |
| } | |
| // Setup your BannerView, review AdSizeCons class for more Ad sizes. | |
| adView = new AdControl | |
| { | |
| ApplicationId = applicationID, | |
| AdUnitId = bannerId, | |
| HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center, | |
| VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom, | |
| Height = height, | |
| Width = width | |
| }; | |
| } | |
| protected override void OnElementChanged(ElementChangedEventArgs<Controls.AdControlView> e) | |
| { | |
| base.OnElementChanged(e); | |
| if(Control == null) | |
| { | |
| CreateNativeAdControl(); | |
| SetNativeControl(adView); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment