c# - Resizing Microsoft Ads -
hi use microsofts ads in uwp app , want ads resize after of app cant work. understand ad control must on of valid sizes (as described here) wrote code resize ad:
private void panel_sizechanged(object sender, sizechangedeventargs e) { if (e.newsize.width >= 728) { ad.width = 728; ad.height = 90; } else if (e.newsize.width >= 640) { ad.width = 640; ad.height = 100; } else if (e.newsize.width >= 480) { ad.width = 480; ad.height = 80; } else if (e.newsize.width >= 320) { ad.width = 320; ad.height = 50; } else if (e.newsize.width >= 300) { ad.width = 300; ad.height = 50; } }
this made control resize accordingly ad inside control looked terrible. added ad.refresh(); @ end didn't change thing.
does know do?
i have faced same problem. unfortunately, ads loaded every 30 seconds , can not refresh them more once in 30 seconds. reason because call refresh() method fails. used workaround hope can you. have "covered" ad stackpanel of same size (and position) of ad. have showed panel when had change size of ad. @ refresh of ad (you can intercept callback adrefreshed), have hidden cover panel.
<stackpanel x:name="adscover" width="300" height="50" visibility="visible" grid.column="0" grid.columnspan="3" horizontalalignment="left" verticalalignment="bottom" canvas.zindex="12" background="whitesmoke"> <border x:name="adsborder" borderbrush="{x:null}" height="50"> <textblock x:name="adsloading" text="ads loading..." horizontalalignment="center" fontstyle="italic" fontfamily="calibri" fontsize="24" textalignment="center" verticalalignment="center"/> </border> </stackpanel> <ui:adcontrol x:name="adsms" applicationid="3f83fe91-d6be-434d-a0ae-7351c5a997f1" adunitid="10865270" horizontalalignment="left" height="50" verticalalignment="bottom" width="300" grid.column="0" grid.columnspan="3" canvas.zindex="10" erroroccurred="onaderroroccurred" adrefreshed="onadrefreshed"/>
in code behind, have change ad size, can this:
... // change size of ad. adsw , adsh new size adsms->setvalue(widthproperty, 1.0*adsw); adsms->setvalue(heightproperty, 1.0*adsh); // cover panel same size adscover->setvalue(widthproperty, 1.0*adsw); adscover->setvalue(heightproperty, 1.0*adsh); adsborder->setvalue(heightproperty, 1.0*adsh); // if size changed, hide ad panel. // in way, can avoid see deformed ad. // m_previousadswidth , m_previousadsheight previous size // of ad. if ((m_previousadswidth != adsw || m_previousadsheight != adsh) && m_previousadswidth > 0 && m_previousadsheight > 0) { adscover->setvalue(visibilityproperty, windows::ui::xaml::visibility::visible); } m_previousadswidth = adsw; m_previousadsheight = adsh; ...
in callback onadrefreshed() can hide panel
// called when ad refreshed. void directxpage::onadrefreshed(platform::object^ sender, windows::ui::xaml::routedeventargs^ e) { // if ad hidden cover panel, make visible again. if (adscover->visibility == windows::ui::xaml::visibility::visible) adscover->setvalue(visibilityproperty, windows::ui::xaml::visibility::collapsed); }
Comments
Post a Comment