CHANDRA
CHANDRA

Reputation: 4928

Issue in creating combobox dynamically

I tried to create a ComboBox dynamically, but cannot create it. Here is the code that I wrote.

        ComboBox com_dynamic = new ComboBox();            
        com_dynamic.Height = 50;
        com_dynamic.Width = 100;           
        LayoutRoot.Children.Add(com_dynamic);           
        tb.Margin = new Thickness(0, 145, 87, 0);
        tb.VerticalAlignment = VerticalAlignment.Top;
        tb.HorizontalAlignment = HorizontalAlignment.Right;

        ComboBoxItem com_dynamic_item = new ComboBoxItem();
        com_dynamic.AddChild(com_dynamic_item);
        com_dynamic_item.Content = "item1";

Upvotes: 0

Views: 137

Answers (1)

vaibhav
vaibhav

Reputation: 1026

You should also add the combobox to a container control. If you want to add it in the LayoutRoot, then this is the line you are missing.

LayoutRoot.Children.Add(com_dynamic);

You can reposition the combobox using its margin in the container.

Upvotes: 2

Related Questions