使用combobox显示另一个combobox C#
一旦我选择了使用combobox显示另一个combobox C#,c#,xaml,combobox,windows-store-apps,windows-8.1,C#,Xaml,Combobox,Windows Store Apps,Windows 8.1,一旦我选择了第一个组合框的第一个项目(学生信息),我想这样做,因为我想显示第二个组合框 我怎样才能做到这一点 在cs代码中 private void first_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { } private void second_ComboBox_SelectionChanged(object sender, SelectionChangedEven
第一个组合框
的第一个项目(学生信息
),我想这样做,因为我想显示第二个组合框
我怎样才能做到这一点
在cs代码中
private void first_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void second_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
在XAML中
<StackPanel Margin="97,47,171,499" Orientation="Horizontal" Grid.Row="1">
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Where You want to Control" VerticalAlignment="Top" Height="82" Width="463" FontSize="36"/>
<ComboBox x:Name="first_ComboBox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="560" Height="42" SelectionChanged="first_ComboBox_SelectionChanged">
<x:String>Student Information</x:String>
<x:String>Staff Information</x:String>
<x:String>Academic Information</x:String>
</ComboBox>
</StackPanel>
<StackPanel Margin="97,172,171,374" Orientation="Horizontal" Grid.Row="1">
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Select the Field" VerticalAlignment="Top" Height="82" Width="463" FontSize="36"/>
<ComboBox x:Name="second_ComboBox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="560" Height="42" SelectionChanged="second_ComboBox_SelectionChanged">
<x:String>Student Name</x:String>
<x:String>Student Address</x:String>
</ComboBox>
</StackPanel>
学生信息
员工信息
学术信息
学名
学生地址
在表单main上,您可以将第二个组合框的可见性设置为false,然后在第一个组合框选择更改时将其设置为true,如下所示
public MainWindow()
{
InitializeComponent();
second_ComboBox.Visibility = Visibility.Collapsed;
}
private void first_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selecteditem = first_ComboBox.SelectedItem as string;
if (selecteditem != null)
{
second_ComboBox.Visibility = Visibility.Visible;
}
}
初始化时使第二个组合框可见隐藏
public MainWindow()
{
InitializeComponent();
second_ComboBox.Visibility = Visibility.Collapsed;
}
private void first_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
first_ComboBox.Visibility = System.Windows.Visibility.Visible;
}
是否要在两个组合框上显示相同的信息?否,我希望在选择第一个组合框的第一项后,在两个不同的列表框中显示第二个组合框嵌入的堆栈面板,然后在您喜欢的任何事件上使用c#代码使其可见或隐藏。可见性=System.Windows.Visibility.Collapsed;prload.Visibility=System.Windows.Visibility.collapsed;聪明的开发者我怎么能做到呢?是的,这是可行的,但我也想知道当学生的信息selected@sahanYugantha因为它触发了第一个ComboBox的selection changed事件,所以我们不能进行自定义选择吗?要打开不同的组合框,请给出一些提示或示例