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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:27:23+00:00 2026-06-03T05:27:23+00:00

I want to create a TextBox, which would have a gray default text appear

  • 0

I want to create a TextBox, which would have a gray “default” text appear in it, if it’s

a) empty

b) has lost focus

when the user enters the text box, the gray “default” text should dissappear.

I’ve tried to do this using ControlTemplate.Triggers, but I can’t seem to find HasFocus property.

What is the best way to do this using XAML?

  • 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-03T05:27:25+00:00Added an answer on June 3, 2026 at 5:27 am

    Whilst there is no real benefit in re-inventing the wheel, it might be interesting to see how this can be done. The easiest way to do this (in pure XAML) is to create a ControlTemplate for the TextBox that overlays a TextBlock when it is not focussed and does not contain text:

    <ControlTemplate TargetType="TextBox">
    <Grid>
        <TextBox Text="{Binding Text, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}" />
        <TextBlock HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Text="Your Prompt Here"
                    Margin="5,0,5,0"
                    Foreground="#FF808080"
                    FontStyle="Italic"
                    IsHitTestVisible="False"
                    x:Name="UserMessage"
                    Visibility="Hidden"/>
    </Grid>
    <ControlTemplate.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="Text" Value=""/>
                <Condition Property="IsKeyboardFocusWithin" Value="False"/>
                </MultiTrigger.Conditions>
            <Setter Property="Visibility" TargetName="UserMessage" Value="Visible"/>
        </MultiTrigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
    

    The MultiTrigger means “set Visibility to Visible if the Text property is empty AND the TextBox does not have keyboard focus”

    If you want to make this more reusable then you could create a custom control with this as it’s default template and with a Dependency Property containing the prompt message

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

Sidebar

Related Questions

I want to create a user control [textbox] which convert all the text in
I want to create a textbox which text binds an integer (e.g 123456789), but
I want to create a textbox, which can be edited and shows the text
I want to create a textbox which contents are validated every time the text
I would want to create a custom UITableViewCell which should have a different appearance
i want to create one textbox which accept city or country name and when
I have an IFrame embedding a youtube video. I want to create a textbox
I'm creating a login page. I want to create ASP.NET TextBox controls that have
To simplify the question, I have a single textbox control which I want to
I want to create span exactly like an input textbox , but inside the

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.