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

  • Home
  • SEARCH
  • 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 8298197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:40:58+00:00 2026-06-08T15:40:58+00:00

On my WPF Window, I want the textboxes to have a slightly blue background

  • 0

On my WPF Window, I want the textboxes to have a slightly blue background when the cursor is on them. I created two simple event handlers (GotFocus and LostFocus) to do this.

private void textBox1_GotFocus(object sender, RoutedEventArgs e)
        {
            textBox1.Background = (Brush)new BrushConverter().ConvertFrom("#FFE6E6FF");
        }

        private void textBox1_LostFocus(object sender, RoutedEventArgs e)
        {
            textBox1.Background = Brushes.White;
        }

Is there a way I can direct every textbox to one eventhandler that gives the background to the respective textbox?

  • 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-06-08T15:41:00+00:00Added an answer on June 8, 2026 at 3:41 pm

    Very simple. Put the event hook on the outermost container of all of the text boxes:

    <Window TextBox.GotFocus="textBox1_GotFocus" TextBox.LostFocus="textBox1_LostFocus">
       <TextBox ... >
       <TextBox ... >
       <TextBox ... >
    </Window>
    

    To make it operate on the correct textbox, cast the “sender” parameter as a textbox:

    private void textBox1_GotFocus(object sender, RoutedEventArgs e)
    {
        ((TextBox)sender).Background = (Brush)new BrushConverter().ConvertFrom("#FFE6E6FF");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two windows in my WPF app: a login window and an options
hello i have a window(wpf) with labels and text boxes, i want him to
I want that my application (a WPF Window ) is launched on Windows startup.
I want to divide my window (wpf) in three columns: left column must be
I am using Avalon in my WPF app. I want a window similar to
I just want to find out how to run two WPF windows (one in
In WPF I have one window opening a second window that allows some data
I have a wpf window which is used to add as well as edit
I have a TextBox in my WPF window. I have a property in the
I am building a WPF application and I have some DependencyProperties in my window's

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.