我对comboBox和ifment有什么问题。 在WindowsForm上它正在工作,但在WPF上工作不好; / 当我选择“标准”没有做什么,当我选择“PhoneBinding”lbl和文本框是可见的,而不是隐藏...我做错了什么?
这是代码:
private void cmbProces_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cmbProces.Text == "Standard")
{
lblUlica.Visibility = Visibility.Visible;
txtUlicaFormatka.Visibility = Visibility.Visible;
}
else if (cmbProces.Text == "Promesa")
{
lblUlica.Visibility = Visibility.Visible;
txtUlicaFormatka.Visibility = Visibility.Visible;
}
else if (cmbProces.Text == "PhoneBinding")
{
lblUlica.Visibility = Visibility.Hidden;
txtUlicaFormatka.Visibility = Visibility.Hidden;
}
}
我也尝试过类似的东西:
if (cmbProces.SelectedValue == "Standard")
{
lblUlica.Visibility = Visibility.Visible;
txtUlicaFormatka.Visibility = Visibility.Visible;
}
else if (cmbProces.SelectedValue == "Promesa")
{
lblUlica.Visibility = Visibility.Visible;
txtUlicaFormatka.Visibility = Visibility.Visible;
}
else if (cmbProces.SelectedValue == "PhoneBinding")
{
lblUlica.Visibility = Visibility.Hidden;
txtUlicaFormatka.Visibility = Visibility.Hidden;
}
}
但也没有工作......任何人都可以说出错了吗?
答案 0 :(得分:0)
我找到了解决方案...... 我在InitializeComponent();
之后添加ItemscmbProces.Items.Add("Standard");
cmbProces.Items.Add("Promesa");
cmbProces.Items.Add("PhoneBinding");
并在xaml文件中删除:
<ComboBoxItems>Standard</ComboBoxItems>
<ComboBoxItems>Promesa</ComboBoxItems>
<ComboBoxItems>PhoneBinding</ComboBoxItems>
这对我有用:)
很抱歉,如果我的问题很愚蠢,但我从WPF开始