在WPF中,如何根据组合框选择使隐藏网格可见?

时间:2017-11-22 13:14:16

标签: c# wpf combobox

当我选择一个组合框项目时,我希望匹配的网格 - 默认情况下是隐藏的 - 变得可见。但是,我的代码似乎不起作用。

private void rating_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
    if (this.rating.SelectedItem == null)
    {
        /*     this.cha1.Visibility = Visibility.Collapsed;
             this.cha1.Visibility = Visibility.Collapsed;
             this.cha2.Visibility = Visibility.Collapsed;
             */
        MessageBox.Show("등급선택을 해주십시오", "알림");
        return;
    }
    else
    {
        string a = rating.SelectedValue.ToString();

        if (a == "1차")
        {
            cha1.Visibility = Visibility.Visible;
            cha1.UpdateLayout();

        }
        if (a == "2차")
        {
            cha2.Visibility = Visibility.Visible;
            cha2.UpdateLayout();
        }
        if (a == "연속")
        {
            cha1.Visibility = Visibility.Visible;
            cha1.UpdateLayout();
        }

    }
}

XAML

<ComboBox 
    Name="rating" 
    HorizontalAlignment="Left" 
    VerticalAlignment="Top" 
    Width="120" 
    Margin="268,4,0,0" 
    SelectionChanged="rating_SelectionChanged_1"
    >
    <ComboBoxItem Content="1차" Tag="Value1"/>
    <ComboBoxItem Content="2차" Tag="Value2"/>
    <ComboBoxItem Content="연속" Tag="Value3"/>

更多XAML

<Grid 
    Name="cha1" 
    HorizontalAlignment="Left" 
    Height="500" 
    VerticalAlignment="Top" 
    Width="390" 
    Margin="0,30,0,0" 
    Visibility="Collapsed"
    >
</Grid>

0 个答案:

没有答案