Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6967949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:23:17+00:00 2026-05-27T16:23:17+00:00

here i want to validate few textboxes by Element Finding on button Click event

  • 0

here i want to validate few textboxes by Element Finding on button Click event

private void button1_Click(object sender, RoutedEventArgs e)
    {
        var button = (Button) sender;

        // button Parent
        var stackPanel = button.Parent as StackPanel;

        // button Parent > parent
        var parentStackPanel = stackPanel.Parent as StackPanel;

        // button Parent > parent > Children
        var childStackPanel = parentStackPanel.Children.Where(a => a is StackPanel).FirstOrDefault() as StackPanel;

        // button Parent > parent > Children >Elements
        var textBox = childStackPanel.Children.Where(a => a is TextBox).FirstOrDefault() as TextBox;
        var image = childStackPanel.Children.Where(a => a is Image).FirstOrDefault() as Image;

        if (textBox.Text == "") image.Source = new BitmapImage(new Uri("/Images/Others/TickWrong.png", UriKind.RelativeOrAbsolute));

    }

the problem is I only able to find First element due to FirstOrDefault()

var childStackPanel = parentStackPanel.Children.Where(a => a is StackPanel).FirstOrDefault() as StackPanel;

is there any possible way to find all the elements .
by Array or something??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:23:18+00:00Added an answer on May 27, 2026 at 4:23 pm

    Remove FirstOrDefault.

    var childStackPanels = parentStackPanel.Children.Where(a => a is StackPanel);
    

    This will return an IEnumerable<T> which you can iterate upon.

    To get a list you can use ToList() extension method of IEnumerable<T>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate my radio button here is my code: <form id=#FormSend> <fieldset>
I want to validate form when click client button out of form, i tryed
Here is my schema and xml file contents. When I want to validate my
I want to validate few inputs before submiting the form, i am doing this
I want to validate just one field of a form. Here is my model:
I want to validate a form element that is allowed to contain multiple email
I have a textbox and a submit button. I want to validate a textbox
I want to validate all the TextBox controls on the page load event. I'm
I'm not entirely sure if I can do what I want here, but I
I've managed to find the Regex to get almost the result I want here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.