后台控制silverlight的Grid
C#代码:
ComboBoxItem item = new ComboBoxItem();
Grid grid = new Grid();
grid.ColumnDefinitions.Insert(0, new ColumnDefinition() { Width = new GridLength(50) });
grid.ColumnDefinitions.Insert(1, new ColumnDefinition() { Width = new GridLength(100) });
Button MyButton = new Button();
MyButton.SetValue(Grid.ColumnProperty, 0);
MyButton.DataContext = "11";
MyButton.Click+=new RoutedEventHandler(MyButton_Click);
TextBox textbox = new TextBox();
textbox.Name = "text";
textbox.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(MyButton);
grid.Children.Add(textbox);
item.Content = grid;
Combobox1.Items.Add(item);
Grid grid = new Grid();
grid.ColumnDefinitions.Insert(0, new ColumnDefinition() { Width = new GridLength(50) });
grid.ColumnDefinitions.Insert(1, new ColumnDefinition() { Width = new GridLength(100) });
Button MyButton = new Button();
MyButton.SetValue(Grid.ColumnProperty, 0);
MyButton.DataContext = "11";
MyButton.Click+=new RoutedEventHandler(MyButton_Click);
TextBox textbox = new TextBox();
textbox.Name = "text";
textbox.SetValue(Grid.ColumnProperty, 1);
grid.Children.Add(MyButton);
grid.Children.Add(textbox);
item.Content = grid;
Combobox1.Items.Add(item);