I'm making a program for window phone using silverlight.
I have a small problem and it is about creating a combo box.
I can create it using xaml, but I am in a situation where I should declare it using c# code.
The problem is after creating a new instance of the combo box and adding the items to it, the combo box doesn't appear!!
The code:
TextBlock tb = new TextBlock();
tb.Text = "Select your arrival status";
tb.Margin = new Thickness(5.0);
tb.FontSize = 20;
tb.Foreground = new SolidColorBrush(Colors.White);
ComboBox cb = new ComboBox();
ObservableCollection<string> testList = new ObservableCollection<string>();
testList.Add("Hi");
testList.Add("Hi1");
testList.Add("Hi2");
cb.DataContext = testList;
cb.Height = 50;
cb.Width = 200;
cb.Foreground = new SolidColorBrush(Colors.White);
panel.Children.Add(tb);
panel.Children.Add(cb);
As you can see from the code, I have declared a TextBlock and a Combobox objects. The TextBox object appears whereas the the Combobox doesn't.
Any help will be appreciated.
Copyright Notice:Content Author:「boring91」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15432788/issue-when-declaring-a-combobox-object-using-c-sharp-code