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 6877689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:37:52+00:00 2026-05-27T04:37:52+00:00

I have created a registration form in silverlight 4, where i have a large

  • 0

I have created a registration form in silverlight 4, where i have a large number of text-boxes, in front of each text box i have placed a text-block as a required field validator, when any of the textbox left empty while loosing focus, the textblock placed in front of it must become red.

textboxes named textbox1, textbox2 … and so as the textblocks

the problem is, i do not want code the specific method for each specific textbox, all i want to do is to complete such in just two three methods

here i did some coding which doesn’t seems to be correct

    private void textBox_LostFocus(object sender, RoutedEventArgs e)
    {
        var textBox = (TextBox) sender;
        if (textbox.Text == "")
           { 
               var textblock = "textblock" +  textBox.Name.Remove(0,7);
               TextblockColorChange(textblock);
           }
    }
    private void TextblockColorChange(object sender)
    {
         var textblock = (TextBlock) sender;
         textblock.Foreground= new SolidColorBrush(Colors.Red);
    }

please suggest some better way to do so..

  • 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-27T04:37:52+00:00Added an answer on May 27, 2026 at 4:37 am

    you need something like this,

    XAML part:

    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Orientation="Horizontal" Height="25">
            <TextBox Width="150" LostFocus="TextBox_LostFocus"/>
            <TextBlock Text="*" Foreground="#FF0000" VerticalAlignment="Center" Margin="10,0,0,0" Visibility="Collapsed"/>
        </StackPanel>
    </Grid>
    

    C# Part:

            private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            var textbox = sender as TextBox;
            if(textbox == null) return;
    
            var stackPanel = textbox.Parent as StackPanel;
            if(stackPanel == null) return;
    
            var textBlock = stackPanel.Children.Where(a => a is TextBlock).FirstOrDefault();
            if (textBlock == null) return;
            if (string.IsNullOrEmpty(textbox.Text)) textBlock.Visibility = Visibility.Visible;
            else textBlock.Visibility = Visibility.Collapsed;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to symfony. I have created a registration form using the code:
I have created Login forms and registration forms for a website. The form is
We have created a registration form in drupal 6 and used cck address field
I have created custom registration form in drupal 6. i have used changed the
I have created a user registration form in CakePHP. My intention is if user
I have created a user registration form using PHP, a password must be entered
I have created a registration form in JSP with an input field for email
I have created a registration form and I send data to the controller. I
I have created a Django app. I have a registration page(simple HTML form) in
I have created a django application. The application has a registration form. I inserted

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.