0

I have little problem with comboBox and if statment. On WindowsForm it's working but on WPF is working bad ;/ When i select "Standard" nothing is doing, when i select "PhoneBinding" lbl and text box is Visible, not hidden... what i doing wrong ?

This is code:

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;
        }

    }

I try also something like that:

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;
        }

    }

But also not working... Can anybody tell what is wrong ?

Radziu
  • 29
  • 3
  • Find out how you're populating your own ComboBox. Use the debugger to find out what SelectedValue is equal to. That's the property you want, not Text. – 15ee8f99-57ff-4f92-890c-b56153 Dec 15 '17 at 14:27
  • 2
    *"On WindowsForm it's working but on WPF is working bad"* - you are trying to do it *winformish* way in wpf, so you must suffer and on occasion discover existence of bindings, command, triggers and whole MVVM world full of wonders. – Sinatr Dec 15 '17 at 14:31
  • We need to know a bit more about the combo box and how your filling it. Without the xaml and code used to populate the combo box I don't think we can give you very much help. [here](https://www.dotnetperls.com/combobox-wpf) is a quick tutorial on wpf combo boxes with basic strings [and this](http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-combobox/) shows a more indepth tutorial with custom objects. – Hack Dec 15 '17 at 14:33
  • Possible duplicate of [ComboBox- SelectionChanged event has old value, not new value](https://stackoverflow.com/questions/2961118/combobox-selectionchanged-event-has-old-value-not-new-value) – Sudsy1002 Dec 15 '17 at 14:35

1 Answers1

1

I found solution.... i add Items after InitializeComponent();

cmbProces.Items.Add("Standard");
cmbProces.Items.Add("Promesa");
cmbProces.Items.Add("PhoneBinding");

And delete in xaml file:

<ComboBoxItems>Standard</ComboBoxItems>
<ComboBoxItems>Promesa</ComboBoxItems>
<ComboBoxItems>PhoneBinding</ComboBoxItems>

And that's work for me :)

Sorry if my question was stupid but I start in WPF

Radziu
  • 29
  • 3