Avatar of Angela4eva
Angela4eva
 asked on

wpf textbox limit text

I have text box in wpf xaml and I want the user to not be able to enter more than 60 characters.. when the starts typing it should tell tem how many charcters they have left to type when they copy paste let them not paste it. I am new to wpf any help appreciated
Programming Languages-OtherProgrammingASP.NET

Avatar of undefined
Last Comment
Angela4eva

8/22/2022 - Mon
gavsmith

Set the MaxLength property of the textbox to 60.

Add a label after the textbox and create an event for the textbox.TextChanged event set the Label.Text to be textbox.MaxLength - textbox.Text.Length + " Characters remaining"

With the MaxLength property set I wouldn't worry about being able to paste it will still only allow 60 chars

Regards
Gav
ASKER CERTIFIED SOLUTION
gavsmith

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Angela4eva

ASKER
great solution. thank you
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck