我正在使用 silverlight 为窗口电话制作程序。
我有一个小问题,它是关于创建一个组合框。
我可以使用 xaml 创建它,但我应该使用 c# 代码声明它。
问题是在创建组合框的新实例并向其中添加项目后,组合框不会出现!!
编码:
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);
从代码中可以看出,我已经声明了一个 TextBlock 和一个 Combobox 对象。TextBox 对象出现,而 Combobox 不出现。
任何帮助将不胜感激。