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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:24:14+00:00 2026-05-26T22:24:14+00:00

Is there an easy way to have a text box display a format in

  • 0

Is there an easy way to have a text box display a format in a text box and remove it when editing ?

Example : I want to ask for a money value. When the user finished entering the value 5.5, it displays $ 5.00 . When the user reclick on the textbox, it should switch back to 5.5 .

Thanks you.

Edit : What I am trying to do would be the equivalent of a converter except the textbox does not have a binding set to it.

  • 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-26T22:24:15+00:00Added an answer on May 26, 2026 at 10:24 pm

    There’s a couple of solutions for this. Perhaps the easiest would be to implement a custom Behavior (you’ll need to reference System.Windows.Interactivity.dll) & hook onto some events TextBox exposes, like GotFocus and LostFocus. Here’s a sample I’ve done for selecting all of a TextBox’s text when it gets focused:

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Interactivity;
    
    namespace TextBoxUtility
    {
        public class TextBoxSelectAllOnFocusBehavior : Behavior<TextBox>
        {
            protected override void OnAttached()
            {
                base.OnAttached();
    
                this.AssociatedObject.PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown;
                this.AssociatedObject.GotKeyboardFocus += OnSelectAll;
                this.AssociatedObject.MouseDoubleClick += OnSelectAll;
            }
    
            protected override void OnDetaching()
            {
                this.AssociatedObject.PreviewMouseLeftButtonDown -= OnPreviewMouseLeftButtonDown;
                this.AssociatedObject.GotKeyboardFocus -= OnSelectAll;
                this.AssociatedObject.MouseDoubleClick -= OnSelectAll;
                base.OnDetaching();
            }
    
            private static void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                var textbox = sender as TextBox;
    
                if (textbox != null && !textbox.IsKeyboardFocusWithin)
                {
                    textbox.Focus();
                    e.Handled = true;
                }
            }
    
            private static void OnSelectAll(object sender, RoutedEventArgs e)
            {
                var textbox = sender as TextBox;
                if (textbox != null)
                {
                    textbox.SelectAll();
                }
            }
    

    Edit: Forgot to show how to hook the behavior up to the TextBox.
    To attach the Behavior, in your XAML you’ll need to add a namespace reference to your Behavior’s namespace, and then attach it as a child of the TextBox markup like so:

    <TextBox Text="{Binding ....}">
        <i:Interaction.Behaviors>
            <utility:TextBoxSelectAllOnFocusBehavior />
        </i:Interaction.Behaviors>
    </TextBox>
    

    You could do something similar, though with yours you’d want to hook up to the LostFocus-related events and adjust the contents of the TextBox’s Text property.

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

Sidebar

Related Questions

Is there an easy way to present time (hh:mm) as a decimal value? Example,
Is there an easy way to have the form helpers set the tabindex parameter
Is there a easy way to do this? Or do I have to parse
I have a workbook with 20 different pivot tables. Is there any easy way
If I have the string .....ZZ..ZZ..... or .Z.1.Z.23Z.4.Z55 , Is there an easy way
I am sure there is no easy way to do this but I have
Is there an easy way to avoid dealing with text encoding problems?
I have a RichTextBox and a button. Is there any easy way to make
I have a text box id=somedate that has a date value 09/27/2009 I'm looking
Is there an easy way to say, on textboxHover, if the text 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.