簡體   English   中英

使用組合框出現另一個組合框C#

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

我想這樣做的原因是,一旦我選擇first_ComboBox的第一項( Student Information )想要出現second_ComboBox

我怎樣才能做到這一點

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

在您的窗體主體上,可以將“第二個組合框”的可見性設置為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;
        }
    }

在初始化時隱藏第二個組合框可見性

    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