public static void DecideAdControl(Grid LayoutRoot, TextBlock txtInfomation) { if (IsAdvertising) { //원할한 광고 수신을 위해 지역 고정 string appId = VersionType == VersionTypes.AMK ? Constant.MS_MK_ADVERTISING_APPID : Constant.MS_TK_ADVERTISING_APPID; string unitId = VersionType == VersionTypes.AMK ? Constant.MS_MK_ADVERTISING_AD_UNIT_ID : Constant.MS_TK_ADVERTISING_AD_UNIT_ID; double width = 480; double height = 80; double txtTopMargin = 60; HorizontalAlignment hAlign = HorizontalAlignment.Left; VerticalAlignment vAlign = VerticalAlignment.Top; Thickness margin = new Thickness(0); //마우스 안내 문구 위치 이동 Thickness txtMargin = txtInfomation.Margin; txtMargin.Top += txtTopMargin; txtInfomation.Margin = txtMargin; Grid adGrd = new Grid(); adGrd.VerticalAlignment = System.Windows.VerticalAlignment.Top; adGrd.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; //my ad ImageButton myAdCtrl = new ImageButton(); myAdCtrl.Width = width; myAdCtrl.Height = height; myAdCtrl.HorizontalAlignment = hAlign; myAdCtrl.VerticalAlignment = vAlign; myAdCtrl.Margin = margin; BitmapImage tn = new BitmapImage(); tn.SetSource(Application.GetResourceStream(UIUtils.GetRelativeUri(ResourceUri.IMG_AD_PLACEHOLDER)).Stream); myAdCtrl.Image = tn; //AdControl msAdCtrl = new AdControl("test_client", "Image480_80", true); AdControl msAdCtrl = new AdControl(appId, unitId, true); AdDuplex.AdControl adDuplexCtrl = new AdDuplex.AdControl() { AppId = Constant.ADDUPLEX_ID }; //adDuplexCtrl.IsTest = true; myAdCtrl.Tap += (s, e) => { //페이지 이동 WebBrowserTask wbt = new WebBrowserTask(); wbt.Uri = new Uri(string.Format("http://windowsphone.com/s?appId={0}", Constant.FULL_VERSION_APP_ID), UriKind.Absolute); wbt.Show(); //광고바 숨김 LayoutRoot.Children.Remove(adGrd); txtMargin.Top -= txtTopMargin; txtInfomation.Margin = txtMargin; }; //adduplex adDuplexCtrl.HorizontalAlignment = hAlign; adDuplexCtrl.VerticalAlignment = vAlign; adDuplexCtrl.Margin = margin; adDuplexCtrl.Width = width; adDuplexCtrl.Height = height; adDuplexCtrl.AdClick += (s, e) => { LayoutRoot.Children.Remove(adGrd); txtMargin.Top -= txtTopMargin; txtInfomation.Margin = txtMargin; }; adDuplexCtrl.AdLoadingError += (s, e) => { if (e.Error.Message != "Ad control is hidden by other control") { Deployment.Current.Dispatcher.BeginInvoke(() => { adGrd.Children.Remove(adDuplexCtrl); //다음광고 호출 adGrd.Children.Add(myAdCtrl); }); } }; //ms ad msAdCtrl.HorizontalAlignment = hAlign; msAdCtrl.VerticalAlignment = vAlign; msAdCtrl.Margin = margin; msAdCtrl.Height = height; msAdCtrl.Width = width; msAdCtrl.IsAutoCollapseEnabled = false; msAdCtrl.ErrorOccurred += (s, e) => { //다음광고 호출 Deployment.Current.Dispatcher.BeginInvoke(() => { adGrd.Children.Remove(msAdCtrl); adGrd.Children.Add(adDuplexCtrl); }); if (System.Diagnostics.Debugger.IsAttached) { MessageBox.Show("MS Advertising : " + e.Error.Message); } }; msAdCtrl.IsEngagedChanged += (s, e) => { LayoutRoot.Children.Remove(adGrd); txtMargin.Top -= txtTopMargin; txtInfomation.Margin = txtMargin; }; TextBlock adTxt = new TextBlock(); adTxt.Margin = new Thickness(485, 0, 0, 0); adTxt.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; adTxt.VerticalAlignment = System.Windows.VerticalAlignment.Center; adTxt.Text = I18n.GetString("AdClickMessage"); adTxt.TextWrapping = TextWrapping.Wrap; adGrd.Children.Add(msAdCtrl); adGrd.Children.Add(adTxt); LayoutRoot.Children.Add(adGrd); } }
//앱바에 아이콘 버튼을 추가하고 이벤트를 연결한다. public static ApplicationBarIconButton CreateAppBarIconButton(string label, string imgPath, EventHandler eventHandler) { return(UIUtils.CreateAppBarIconButton(label, UIUtils.GetRelativeUri(imgPath), eventHandler)); }