0

我正在使用 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 不出现。

任何帮助将不胜感激。

4

1 回答 1

0

你需要给它分配一个位置。您的组合框很可能位于您的文本框下方。要么使用设计器和 xaml 创建它们两个,要么确保为它们分配 x,y 坐标。使用 Margin 属性以及 Horizo​​ntalAlignment 和 VerticalAlignment。

于 2013-03-15T12:48:16.943 回答