braddo
braddo

Reputation: 71

If selecteditem not null textbox becomes visible

I have a UWP app in C# with XAML.
I have various comboboxes and textboxes.
I would like to create an event with the following: When a combobox item is selected from combo1, textbox becomes visible.

I know the combobox property is Visibility:Visble/collapsed not sure how to incorporate this into my event as i can't get the textbox.visibility property to work

private void ComboboxItem_Chosen(object sender, RoutedEventArgs e)
    {
        if (combobox.SelectedText != null)
        {
            txttnumber.Visibility ??
        }
        else
        {
            combobox.Visibility ??
        }
    }

Upvotes: 1

Views: 281

Answers (2)

sujith karivelil
sujith karivelil

Reputation: 29036

The Visibility under System.Windows will allows you to change the visibility of the object. You can set It

Visible : Display the element.

Hidden : Do not display the element, but reserve space for the element in layout.

Collapsed : Do not display the element, and do not reserve space for it in layout. Elements that have a Visibility value of Collapsed do not occupy any layout space. By default, elements are Visible.

So In your case you should use like the following:

private void ComboboxItem_Chosen(object sender, RoutedEventArgs e)
{
    if (combobox.SelectedText != null)
    {
        txttnumber.Visibility = Visibility.Visible;
    }
    else
    {
        combobox.Visibility = Visibility.Collapsed;
    }
}

Upvotes: 0

Apoorv
Apoorv

Reputation: 2043

You Could get it done like this

private void ComboboxItem_Chosen(object sender, RoutedEventArgs e)
 { 
if (combobox.SelectedText != null)
 { txttnumber.Visibility =Visibility.Visible;
 } 
else 
{ combobox.Visibility =Visibility.Collapsed; 
}
 }

Upvotes: 1

Related Questions