Windows phone7 動態添加控制項2011-03-29 3:48
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace testbywgscd
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 5; i++)
{
var checkbox = new CheckBox
{
Content = "inbox",
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
FontFamily = new FontFamily("Calibri"),
FontSize = 30,
Margin= new Thickness(11,i*101,0,0),
Width=101,
Height=101,
};
checkbox.Checked +=new RoutedEventHandler(checkbox_Checked);
ContentPanel.Children.Add(checkbox); //ContentPanel is grid control
// FrameworkDispatcher.Update();
// Grid.SetRow(checkbox, i + 10);
// Grid.SetRow(checkbox, i + 10);
}
}
void checkbox_Checked(object o, RoutedEventArgs e) {
MessageBox.Show("hello6");
}
}
}