简体   繁体   English

使用组合框出现另一个组合框C#

[英]use of combobox to appear another combobox C#

I want to make this as, once i select the first item( Student Information ) of the first_ComboBox want to appear second_ComboBox . 我想这样做的原因是,一旦我选择first_ComboBox的第一项( Student Information )想要出现second_ComboBox

How can I make this happen 我怎样才能做到这一点

In the cs code 在cs代码中

private void first_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

    }

    private void second_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

    }

in XAML 在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>

On your Form main, you can set the visibility of Second Combobox to be false, and then on the first combobox selection changed set it to true, Something like this 在您的窗体主体上,可以将“第二个组合框”的可见性设置为false,然后在将第一个组合框选择更改为“ true”时,将其设置为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;
        }
    }

on initialization make second combobox visiblity hidden 在初始化时隐藏第二个组合框可见性

    public MainWindow()
{
    InitializeComponent();
    second_ComboBox.Visibility = Visibility.Collapsed;
}

private void first_ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
       first_ComboBox.Visibility = System.Windows.Visibility.Visible;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM