好吧,我似乎陷入困境,不知道为什么
我创建了广告代码:
AdControl myad = new AdControl("test_client", "Image480_80", true);
myad.Width = 480;
myad.Height = 80;
稍后在循环中我有
if (r % 3 == 0)
{
ContentPanel.Children.Add(myad);
r++;
}
TextBlock txt = new TextBlock();
txt.TextWrapping = TextWrapping.Wrap;
txt.Text = s.Name;
Button btn = new Button();
btn.Name = "btn" + a.ToString();
btn.Content = txt;
btn.Width = SCREENWIDTH / BUTTONSPERROW;
btn.Height = btn.Width;
btn.Background = new SolidColorBrush((App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color);
btn.VerticalAlignment = System.Windows.VerticalAlignment.Top;
btn.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
btn.Click += btn_Click;
btn.Hold += btn_Hold;
btn.Tag = s;
btn.Margin = new Thickness((SCREENWIDTH / BUTTONSPERROW) * c, r * 150, 0, 0);
ContentPanel.Children.Add(btn);
//work out next position
if (c == BUTTONSPERROW - 1) { c = 0; r++; }
else { c++; }
a++;
在添加广告专线ContentPanel.Children.Add(myad);
之前一切正常
我发表评论说这一切都有效,并且还有一个差距。
鉴于ContentPanel.Children.Add(btn);
行正常工作,我很困惑为什么myad行无效。有什么想法吗?
答案 0 :(得分:1)
在循环中创建新的AdControl
并添加如下
if (r % 3 == 0)
{
AdControl myad = new AdControl("test_client" + r, "Image480_80", true);
myad.Width = 480;
myad.Height = 80;
ContentPanel.Children.Add(myad);
r++;
}