我需要在运行时创建一个包含人员姓名的组合框,并使用数据数组填充该组合框,并将其开口绑定到一个按钮。
即使设置了高度,它也不会打开。它在XAML文件中不存在,必须由运行时创建。

每当我调试Height时,它总是设置为0;

ComboBox peopleComboBox = new ComboBox();
List <Person> people; //it's initialized elsewhere
private void btnLoadPeopleName_Click(object sender, RoutedEventArgs e)
    {

        peopleComboBox.IsEnabled = true;
        peopleComboBox.Height = 1280; //I wanted to set it Auto with double.NaN but it won't open. Always set to 0 during debugging.

        peopleComboBox.ItemsSource = people;
        peopleComboBox.DisplayMemberPath = "first_name";
        peopleComboBox.SelectedIndex = 0;

        peopleComboBox .SelectionChanged +=peopleComboBox_SelectionChanged;

        peopleComboBox.Visibility = Visibility.Visible;
        peopleComboBox.IsDropDownOpen = true; //this should open it, right?
    }


我究竟做错了什么?

最佳答案

就像@ChrisF评论一样,您是否要将此comboBox添加到视图中?如果没有,则将其添加到父容器组件。
gridComponent.Children.Add(yourComboBox)

至于Height,您正在做什么是正确的。

关于c# - 在运行时创建的ComboBox将不会显示Windows Phone 8.1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34841396/

10-09 10:18