Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How do I avoid adding empty listbox items?

$
0
0

I have a textbox that takes user input, the input is added to a listbox, how do I set it so that the user can't add an empty string to the listbox?

<TextBox x:Name="txtNewCategory"
                             Grid.Row="1"
                             Width="400"
                             Height="25"
                             Margin="10"
                             Text="{Binding UserInput, Mode=TwoWay}"><TextBox.Effect><DropShadowEffect BlurRadius="5"
                                              ShadowDepth="3" /></TextBox.Effect></TextBox>

private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ViewModelAddCategoriesWindow dataContext = (ViewModelAddCategoriesWindow)this.DataContext;
                this.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


Viewing all articles
Browse latest Browse all 18858

Trending Articles