在运行时创建的 ComboBox 不会显示 Windows Phone 8.1
ComboBox created in runtime won't show Windows Phone 8.1
我需要在运行时创建一个包含人名的组合框,用数据数组填充它,并将其开口绑定到一个按钮。
即使我设置了高度,它也不会打开。它不存在于 XAML 文件中,它必须由运行时创建。
每当我调试高度时,它总是设置为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 评论一样,您是否将此组合框添加到您的视图中?如果不将其添加到父 Container 组件。
gridComponent.Children.Add(yourComboBox)
至于Height
你做的是对的。
我需要在运行时创建一个包含人名的组合框,用数据数组填充它,并将其开口绑定到一个按钮。 即使我设置了高度,它也不会打开。它不存在于 XAML 文件中,它必须由运行时创建。
每当我调试高度时,它总是设置为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 评论一样,您是否将此组合框添加到您的视图中?如果不将其添加到父 Container 组件。
gridComponent.Children.Add(yourComboBox)
至于Height
你做的是对的。